Title: tight_layout reserves tick space even if disabled · Issue #11203 · matplotlib/matplotlib · GitHub
Open Graph Title: tight_layout reserves tick space even if disabled · Issue #11203 · matplotlib/matplotlib
X Title: tight_layout reserves tick space even if disabled · Issue #11203 · matplotlib/matplotlib
Description: Bug report tight_layout seems to reserve space for axes ticks even if they are removed I like to save a plot with zero surrounding whitespace. Previously (version 1.5.3) this was possible by setting bbox_inches='tight', pad_inches=0 in t...
Open Graph Description: Bug report tight_layout seems to reserve space for axes ticks even if they are removed I like to save a plot with zero surrounding whitespace. Previously (version 1.5.3) this was possible by settin...
X Description: Bug report tight_layout seems to reserve space for axes ticks even if they are removed I like to save a plot with zero surrounding whitespace. Previously (version 1.5.3) this was possible by settin...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/11203
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tight_layout reserves tick space even if disabled","articleBody":"### Bug report\r\n\r\n**tight_layout seems to reserve space for axes ticks even if they are removed**\r\n\r\nI like to save a plot with zero surrounding whitespace. \r\n\r\nPreviously (version 1.5.3) this was possible by setting `bbox_inches='tight', pad_inches=0` in the `savefig` call and removing any axis decorators (ticks, labels). In the current version (version 2.2.2) the whitespace around the plot cannot be fully removed in the above way, even if decorators are removed. It seems that the remaining whitespace corresponds to the area that the axis ticks would be drawn in, had they not been removed.\r\n\r\nThis seems to be related to [recent changes](https://matplotlib.org/2.2.2/users/whats_new.html#axes-legends-now-included-in-tight-bbox) in how axes legends get drawn:\r\n```\r\nTools like fig.tight_layout() and fig.savefig(bbox_inches='tight') \r\nwould clip these legends. \r\nA change was made to include them in the tight calculations.\r\n```\r\n\r\nIt seems not possible to save a plot with no surrounding whitespace in the current version.\r\n\r\n**Code for reproduction**\r\n\r\n```python\r\nimport numpy as np\r\nfrom matplotlib import pyplot as plt\r\n\r\n# axis ticks drawn\r\nf = plt.figure(figsize=(1,1))\r\nax = f.add_subplot(111)\r\nax.matshow(np.ones((10,10)), cmap=plt.cm.Blues_r, aspect='auto')\r\nax.set_xticklabels([])\r\nax.set_yticklabels([])\r\n#ax.axis('off')\r\nf.savefig('test_ticks.png', dpi=300, bbox_inches='tight', pad_inches=0, facecolor='red')\r\n\r\n# axis ticks removed\r\nf = plt.figure(figsize=(1,1))\r\nax = f.add_subplot(111)\r\nax.matshow(np.ones((10,10)), cmap=plt.cm.Blues_r, aspect='auto')\r\nax.set_xticklabels([])\r\nax.set_yticklabels([])\r\nax.axis('off')\r\nf.savefig('test_noticks.png', dpi=300, bbox_inches='tight', pad_inches=0, facecolor='red')\r\n```\r\n\r\n**Actual outcome (using matplotlib 2.2.2)**\r\n`test_ticks.png`:\r\n\r\nimage dimensions: 239 * 232 pixels\r\n\r\n`test_noticks.png`:\r\n\r\nimage dimensions: 239 * 232 pixels\r\n\r\n**Expected outcome (using matplotlib 1.5.3)**\r\n`test_ticks.png`:\r\n\r\nimage dimensions: 232 * 232 pixels\r\n(drawing the ticks inside the plot is obviously not desirable as well but I think this illustrates the difference in behaviour)\r\n\r\n`test_noticks.png`:\r\n\r\nimage dimensions: 232 * 232 pixels\r\n(this is what I'd like to get with the above code).\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: Ubuntu 16.04 LTS\r\n * Matplotlib version: 2.2.2\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): `module://ipykernel.pylab.backend_inline` (also tried in Qt5Agg)\r\n * Python version: 3.6.5\r\n * Jupyter version (if applicable): 4.4.0\r\n * Other libraries: \r\n```\r\nbackcall==0.1.0\r\ncertifi==2018.4.16\r\ncycler==0.10.0\r\nCython==0.28.2\r\ndecorator==4.3.0\r\nipykernel==4.8.2\r\nipython==6.3.1\r\nipython-genutils==0.2.0\r\njedi==0.12.0\r\njupyter-client==5.2.3\r\njupyter-core==4.4.0\r\nkiwisolver==1.0.1\r\nmatplotlib==2.2.2\r\nmkl-fft==1.0.0\r\nmkl-random==1.0.1\r\nnibabel==2.2.1\r\nnilearn==0.4.1\r\nnumpy==1.14.2\r\nolefile==0.45.1\r\nparso==0.2.0\r\npexpect==4.5.0\r\npickleshare==0.7.4\r\nPillow==5.1.0\r\nprompt-toolkit==1.0.15\r\nptyprocess==0.5.2\r\nPygments==2.2.0\r\npyparsing==2.2.0\r\nPyQt5==5.10.1\r\npython-dateutil==2.7.2\r\npytz==2018.4\r\npyzmq==17.0.0\r\nscikit-learn==0.19.1\r\nscipy==1.0.1\r\nsimplegeneric==0.8.1\r\nsip==4.19.8\r\nsix==1.11.0\r\ntornado==5.0.2\r\ntraitlets==4.3.2\r\nwcwidth==0.1.7\r\n```\r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\nAll throught conda default channel, the code example was run in two separate virtual environments, one downgraded to matplotlib 1.5.3.\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n","author":{"url":"https://github.com/surchs","@type":"Person","name":"surchs"},"datePublished":"2018-05-09T00:32:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/11203/matplotlib/issues/11203"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:42c2c2ed-5228-197a-d885-c076e8b734d3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCBE:942D6:43AB2:5DD7A:6A5461BB |
| html-safe-nonce | 06a749c25ad16bdf95cb73852f7c679532ddfde84a33827548e59ddc6b73e1f7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0JFOjk0MkQ2OjQzQUIyOjVERDdBOjZBNTQ2MUJCIiwidmlzaXRvcl9pZCI6IjczMDUzNzA2NDA3NDc2MTg3NDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 87883b168238bd8be4e5a6add0ca66e34c28a5100eb3000bda00cab03ae5b6e8 |
| hovercard-subject-tag | issue:321391376 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/11203/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4bbe34345a13599838f6efc9d607a2ff3ad8f72d3ef1a3a7b79d9e2ce57a8c88/matplotlib/matplotlib/issues/11203 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4bbe34345a13599838f6efc9d607a2ff3ad8f72d3ef1a3a7b79d9e2ce57a8c88/matplotlib/matplotlib/issues/11203 |
| og:image:alt | Bug report tight_layout seems to reserve space for axes ticks even if they are removed I like to save a plot with zero surrounding whitespace. Previously (version 1.5.3) this was possible by settin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | surchs |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6d28624802c2f7d9500239dd6870ed7031b7353b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width