Title: Constrained Layout tutorial needs some cleanup.... · Issue #12391 · matplotlib/matplotlib · GitHub
Open Graph Title: Constrained Layout tutorial needs some cleanup.... · Issue #12391 · matplotlib/matplotlib
X Title: Constrained Layout tutorial needs some cleanup.... · Issue #12391 · matplotlib/matplotlib
Description: Originally posted by @ImportanceOfBeingErnest in #12377 (comment) The code does not seem to be runnable and does not give a sensible result. I used this code fig, axs = plt.subplots(2, 2, constrained_layout=True) for ax in axs.flatten()[...
Open Graph Description: Originally posted by @ImportanceOfBeingErnest in #12377 (comment) The code does not seem to be runnable and does not give a sensible result. I used this code fig, axs = plt.subplots(2, 2, constrain...
X Description: Originally posted by @ImportanceOfBeingErnest in #12377 (comment) The code does not seem to be runnable and does not give a sensible result. I used this code fig, axs = plt.subplots(2, 2, constrain...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/12391
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Constrained Layout tutorial needs some cleanup....","articleBody":"_Originally posted by @ImportanceOfBeingErnest in https://github.com/matplotlib/matplotlib/pull/12377#issuecomment-426807732_\r\n\r\nThe code does not seem to be runnable and does not give a sensible result. I used this code\r\n\r\n```\r\nfig, axs = plt.subplots(2, 2, constrained_layout=True)\r\nfor ax in axs.flatten()[:-1]:\r\n ax.plot(np.arange(10))\r\naxs[1, 1].plot(np.arange(10), label='This is a plot')\r\nleg = axs[1, 1].legend(loc='center left', bbox_to_anchor=(0.8, 0.5))\r\nleg.set_in_layout(False)\r\nwanttoprint = True\r\nif wanttoprint:\r\n leg.set_in_layout(True)\r\n fig.do_constrained_layout(False)\r\n fig.savefig('outname.png', bbox_inches='tight')\r\nplt.show()\r\n```\r\n\r\ni.e. the code from the [matplotlib 3.0 documentation](https://matplotlib.org/tutorials/intermediate/constrainedlayout_guide.html#legends) with `wanttoprint = True` but it gives an error `AttributeError: 'Figure' object has no attribute 'do_constrained_layout'`.\r\n\r\nAssuming that what is meant here is `set_constrained_layout`, the problem is that the figure shown deviates from the one obtained via `wanttoprint = False`. So it seems it's not possible to show the figure after saving it?\r\n\r\nUsing the second code (the one with `fig.legend()`) everything works as expected.\r\n\r\nIn my eyes there are the following things to do:\r\n\r\n1. Correct the first code to be runnable and produce the expected outcome for both settings of `wanttoprint` on screen and as saved image.\r\n2. Explain the reasoning behind turning the legend in layout option first off then on etc.\r\n3. Add a savefig line to the second example to make is clear that this is to be understood parallel to the previous example.\r\n","author":{"url":"https://github.com/jklymak","@type":"Person","name":"jklymak"},"datePublished":"2018-10-03T21:36:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/12391/matplotlib/issues/12391"}
| 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:92af8534-3c11-0aae-809d-3c22cd132c11 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E89A:11304E:1D7CCA0:2879CB9:6A54049C |
| html-safe-nonce | babb4eeb6d2d55909370d9eecab1f8b3ed5032efa98ad2747aeef9612dc3054e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODlBOjExMzA0RToxRDdDQ0EwOjI4NzlDQjk6NkE1NDA0OUMiLCJ2aXNpdG9yX2lkIjoiNjk4MDc0NzQ1NjIxMzY4MTMwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ed84a4ceaae63ded0d6d4488afd3bc5bb0feac2b231ec3039144a6ee6cd84ade |
| hovercard-subject-tag | issue:366539317 |
| 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/12391/issue_layout |
| twitter:image | https://opengraph.githubassets.com/16f61bab208b1c0556209b2220cdefce626f7325e36df606c468b53bbc73d153/matplotlib/matplotlib/issues/12391 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/16f61bab208b1c0556209b2220cdefce626f7325e36df606c468b53bbc73d153/matplotlib/matplotlib/issues/12391 |
| og:image:alt | Originally posted by @ImportanceOfBeingErnest in #12377 (comment) The code does not seem to be runnable and does not give a sensible result. I used this code fig, axs = plt.subplots(2, 2, constrain... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jklymak |
| 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