Title: Tutorial pyplot_scales.py crashes when used with plt.tight_layout() · Issue #6789 · matplotlib/matplotlib · GitHub
Open Graph Title: Tutorial pyplot_scales.py crashes when used with plt.tight_layout() · Issue #6789 · matplotlib/matplotlib
X Title: Tutorial pyplot_scales.py crashes when used with plt.tight_layout() · Issue #6789 · matplotlib/matplotlib
Description: Trying to replace plt.subplots_adjust with plt.tight_layout in the pyplot tutorial pyplot_scales.py (see #6779), seems to results in errors. Matplotlib version, Python version and Platform (Windows, OSX, Linux ...): Linux (at least Archl...
Open Graph Description: Trying to replace plt.subplots_adjust with plt.tight_layout in the pyplot tutorial pyplot_scales.py (see #6779), seems to results in errors. Matplotlib version, Python version and Platform (Windows...
X Description: Trying to replace plt.subplots_adjust with plt.tight_layout in the pyplot tutorial pyplot_scales.py (see #6779), seems to results in errors. Matplotlib version, Python version and Platform (Windows...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/6789
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tutorial pyplot_scales.py crashes when used with plt.tight_layout()","articleBody":"Trying to replace `plt.subplots_adjust` with `plt.tight_layout` in the pyplot tutorial `pyplot_scales.py` (see #6779), seems to results in errors.\n- [x] Matplotlib version, Python version and Platform (Windows, OSX, Linux ...):\n- Linux (at least Archlinux and CentOs 7)\n- Tested on mpl 1.5.1 from Anaconda and mpl 2.0.0b3.post1799+ga4fdd60 from github\n- [x] MWE (kind of…):\n Based on `pyplot_scales.py`:\n\n``` python\nimport numpy as np\nimport matplotlib.pyplot as plt\nplt.style.use('default')\n\n# make up some data in the interval ]0, 1[\ny = np.random.normal(loc=0.5, scale=0.4, size=1000)\ny = y[(y \u003e 0) \u0026 (y \u003c 1)]\ny.sort()\nx = np.arange(len(y))\n\nplt.figure(1)\nplt.subplot(221)\nplt.subplot(222)\nplt.subplot(223)\n\n# logit\nplt.subplot(224)\nplt.plot(x, y)\nplt.yscale('logit')\n#plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,\n# wspace=0.35)\nplt.tight_layout()\n\nplt.show()\n```\n\nWhen I run this example with `plt.tight_layout` instead of `plt.subplots_adjust` (or simply no subplot layout adjusting at all), I get these outputs (mpl 2.0.0b3.post1799+ga4fdd60):\n- with Qt4Agg backend\n\n```\nIn [1]: run pyplot_scales_mwe.py # that's the MWE posted above\n/home/adrien/matplotlib/lib/matplotlib/transforms.py:380: RuntimeWarning: invalid value encountered in double_scalars\n return points[1, 0] - points[0, 0]\n/home/adrien/matplotlib/lib/matplotlib/tight_layout.py:199: RuntimeWarning: invalid value encountered in double_scalars\n kwargs[\"wspace\"] = hspace / h_axes\n/home/adrien/matplotlib/lib/matplotlib/axis.py:1008: UserWarning: Unable to find pixel distance along axis for interval padding of ticks; assuming no interval padding needed.\n warnings.warn(\"Unable to find pixel distance along axis \"\n/home/adrien/matplotlib/lib/matplotlib/axis.py:1018: UserWarning: Unable to find pixel distance along axis for interval padding of ticks; assuming no interval padding needed.\n warnings.warn(\"Unable to find pixel distance along axis \"\n\nTraceback (most recent call last):\n File \"/home/adrien/matplotlib/lib/matplotlib/backends/backend_qt5agg.py\", line 182, in __draw_idle_agg\n FigureCanvasAgg.draw(self)\n File \"/home/adrien/matplotlib/lib/matplotlib/backends/backend_agg.py\", line 464, in draw\n self.figure.draw(self.renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/artist.py\", line 68, in draw_wrapper\n return draw(artist, renderer, *args, **kwargs)\n File \"/home/adrien/matplotlib/lib/matplotlib/figure.py\", line 1262, in draw\n renderer, self, dsu, self.suppressComposite)\n File \"/home/adrien/matplotlib/lib/matplotlib/image.py\", line 139, in _draw_list_compositing_images\n a.draw(renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/artist.py\", line 68, in draw_wrapper\n return draw(artist, renderer, *args, **kwargs)\n File \"/home/adrien/matplotlib/lib/matplotlib/axes/_base.py\", line 2383, in draw\n mimage._draw_list_compositing_images(renderer, self, dsu)\n File \"/home/adrien/matplotlib/lib/matplotlib/image.py\", line 139, in _draw_list_compositing_images\n a.draw(renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/artist.py\", line 68, in draw_wrapper\n return draw(artist, renderer, *args, **kwargs)\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 1109, in draw\n ticks_to_draw = self._update_ticks(renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 942, in _update_ticks\n tick_tups = [t for t in self.iter_ticks()]\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 885, in iter_ticks\n majorLocs = self.major.locator()\n File \"/home/adrien/matplotlib/lib/matplotlib/ticker.py\", line 1721, in __call__\n return self.tick_values(vmin, vmax)\n File \"/home/adrien/matplotlib/lib/matplotlib/ticker.py\", line 1726, in tick_values\n locs = self._raw_ticks(vmin, vmax)\n File \"/home/adrien/matplotlib/lib/matplotlib/ticker.py\", line 1674, in _raw_ticks\n nbins = max(min(self.axis.get_tick_space(), 9),\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 2008, in get_tick_space\n return int(np.floor(length / size))\nValueError: cannot convert float NaN to integer\n```\n\nwhich results in\n\n(NB: it's a screenshot because `savefig` complained about the “ValueError: cannot convert float NaN to integer” stuff)\n- with TkAgg backend\n\n```\nIn [1]: run pyplot_scales_mwe.py # that's again the MWE posted above\n/home/adrien/matplotlib/lib/matplotlib/transforms.py:380: RuntimeWarning: invalid value encountered in double_scalars\n return points[1, 0] - points[0, 0]\n/home/adrien/matplotlib/lib/matplotlib/tight_layout.py:199: RuntimeWarning: invalid value encountered in double_scalars\n kwargs[\"wspace\"] = hspace / h_axes\n/home/adrien/matplotlib/lib/matplotlib/axis.py:1008: UserWarning: Unable to find pixel distance along axis for interval padding of ticks; assuming no interval padding needed.\n warnings.warn(\"Unable to find pixel distance along axis \"\n/home/adrien/matplotlib/lib/matplotlib/axis.py:1018: UserWarning: Unable to find pixel distance along axis for interval padding of ticks; assuming no interval padding needed.\n warnings.warn(\"Unable to find pixel distance along axis \"\n\nException in Tkinter callback\nTraceback (most recent call last):\n File \"/home/adrien/anaconda/envs/Python2.7_matplotlib-git/lib/python2.7/lib-tk/Tkinter.py\", line 1536, in __call__\n return self.func(*args)\n File \"/home/adrien/matplotlib/lib/matplotlib/backends/backend_tkagg.py\", line 283, in resize\n self.show()\n File \"/home/adrien/matplotlib/lib/matplotlib/backends/backend_tkagg.py\", line 354, in draw\n FigureCanvasAgg.draw(self)\n File \"/home/adrien/matplotlib/lib/matplotlib/backends/backend_agg.py\", line 464, in draw\n self.figure.draw(self.renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/artist.py\", line 68, in draw_wrapper\n return draw(artist, renderer, *args, **kwargs)\n File \"/home/adrien/matplotlib/lib/matplotlib/figure.py\", line 1262, in draw\n renderer, self, dsu, self.suppressComposite)\n File \"/home/adrien/matplotlib/lib/matplotlib/image.py\", line 139, in _draw_list_compositing_images\n a.draw(renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/artist.py\", line 68, in draw_wrapper\n return draw(artist, renderer, *args, **kwargs)\n File \"/home/adrien/matplotlib/lib/matplotlib/axes/_base.py\", line 2383, in draw\n mimage._draw_list_compositing_images(renderer, self, dsu)\n File \"/home/adrien/matplotlib/lib/matplotlib/image.py\", line 139, in _draw_list_compositing_images\n a.draw(renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/artist.py\", line 68, in draw_wrapper\n return draw(artist, renderer, *args, **kwargs)\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 1109, in draw\n ticks_to_draw = self._update_ticks(renderer)\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 942, in _update_ticks\n tick_tups = [t for t in self.iter_ticks()]\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 885, in iter_ticks\n majorLocs = self.major.locator()\n File \"/home/adrien/matplotlib/lib/matplotlib/ticker.py\", line 1721, in __call__\n return self.tick_values(vmin, vmax)\n File \"/home/adrien/matplotlib/lib/matplotlib/ticker.py\", line 1726, in tick_values\n locs = self._raw_ticks(vmin, vmax)\n File \"/home/adrien/matplotlib/lib/matplotlib/ticker.py\", line 1674, in _raw_ticks\n nbins = max(min(self.axis.get_tick_space(), 9),\n File \"/home/adrien/matplotlib/lib/matplotlib/axis.py\", line 2008, in get_tick_space\n return int(np.floor(length / size))\nValueError: cannot convert float NaN to integer\n```\n\nwhich produces an empty figure.\n- [x] If this is an image generation bug attach a screenshot demonstrating the issue:\n See above.\n- [x] If this is a regression (Used to work in an earlier version of Matplotlib), please \n note where it used to work:\n The behavior seems to be the same with mpl 1.5.1 and (at least) both TkAgg and Qt4Agg backends.\n","author":{"url":"https://github.com/afvincent","@type":"Person","name":"afvincent"},"datePublished":"2016-07-18T08:46:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/6789/matplotlib/issues/6789"}
| 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:ae95338b-c805-96f3-fc5a-81923dba58de |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EBDA:39E76C:1CB3352:271289C:6A5400CE |
| html-safe-nonce | 9cef075f9b4f81a65abd8a8567b73857af5b6908d1da3db19cdef70c845989c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkRBOjM5RTc2QzoxQ0IzMzUyOjI3MTI4OUM6NkE1NDAwQ0UiLCJ2aXNpdG9yX2lkIjoiODAyOTYyOTA4NjA4NjQ2MzY5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b8ee17587f8dc92cc1fc33711c06d1ab5c9bbd50d49573394fe5f950babe9822 |
| hovercard-subject-tag | issue:166046826 |
| 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/6789/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b41dec635e5fe7f217a9cbfa643589896f9fdad23a3c539576e9c491f8cdd38b/matplotlib/matplotlib/issues/6789 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b41dec635e5fe7f217a9cbfa643589896f9fdad23a3c539576e9c491f8cdd38b/matplotlib/matplotlib/issues/6789 |
| og:image:alt | Trying to replace plt.subplots_adjust with plt.tight_layout in the pyplot tutorial pyplot_scales.py (see #6779), seems to results in errors. Matplotlib version, Python version and Platform (Windows... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | afvincent |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width