Title: Native support for showing OOP-created figures · Issue #19956 · matplotlib/matplotlib · GitHub
Open Graph Title: Native support for showing OOP-created figures · Issue #19956 · matplotlib/matplotlib
X Title: Native support for showing OOP-created figures · Issue #19956 · matplotlib/matplotlib
Description: Problem Often, I will create figures using matplotlib using the Figure class explicitly, because either I want to make a figure and repeatedly tweak it to see how it looks, or I am creating a lot of figures and don't need / want to deal ...
Open Graph Description: Problem Often, I will create figures using matplotlib using the Figure class explicitly, because either I want to make a figure and repeatedly tweak it to see how it looks, or I am creating a lot o...
X Description: Problem Often, I will create figures using matplotlib using the Figure class explicitly, because either I want to make a figure and repeatedly tweak it to see how it looks, or I am creating a lot o...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/19956
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Native support for showing OOP-created figures","articleBody":"### Problem\r\n\r\nOften, I will create figures using matplotlib using the ``Figure`` class explicitly, because either I want to make a figure and repeatedly tweak it to see how it looks, or I am creating a lot of figures and don't need / want to deal with the pyplot interface. However, as far as I can tell, there is no native matplotlib way to show those figures since they weren't created with the pyplot interface.\r\n\r\nAn example of what I would like to do:\r\n```\r\nfig =. Figure()\r\nax = fig.subplots()\r\nax.plot([1, 2, 3, 4])\r\nfig.show() # This gives an error (below)\r\n```\r\n\r\nError:\r\n```\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"/Users/jordan.e/opt/miniconda3/lib/python3.7/site-packages/matplotlib/figure.py\", line 408, in show\r\n \"Figure.show works only for figures managed by pyplot, \"\r\nAttributeError: Figure.show works only for figures managed by pyplot, normally created by pyplot.figure()\r\n```\r\n\r\nThe reason I don't want to use ``plt.subplots()`` followed by ``plt.show()``, is, as mentioned above, because I often want to close and re-show the same figure. It seems really odd to me that matplotlib has a way of creating figures via a pure-OOP interface, but no easy way to display them. This is very frustrating and basically leads me to either repeatedly re-create the same plot with the pyplot interface instead of just tweaking the one I already have. I wrote a very hacky method for showing created figures based on a StackOverflow answer to this question which is below, and does not work reliably (the figure doubles in size every time I show it):\r\n\r\n```\r\ndef show_figure(fig):\r\n \"\"\"\r\n create a dummy figure and use its manager to display \"fig\"\r\n \"\"\"\r\n\r\n dummy = plt.figure()\r\n new_manager = dummy.canvas.manager\r\n new_manager.canvas.figure = fig\r\n fig.set_canvas(new_manager.canvas)\r\n plt.show()\r\n```\r\n\r\n### Proposed Solution\r\n\r\nEither support ``fig.show()`` directly for figures created using the OOP-interface, or provide a method like ``pyplot.show_figure()`` which takes as an argument an existing figure and prints it to the screen (doing the exact same thing that a ``plt.plot()`` followed by ``plt.show()`` would do)","author":{"url":"https://github.com/edmundsj","@type":"Person","name":"edmundsj"},"datePublished":"2021-04-14T01:44:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/19956/matplotlib/issues/19956"}
| 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:efce250d-0a37-fc51-57cc-16f436fdfe62 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC14:1E91F2:6CF2B2:707B2B:6A520027 |
| html-safe-nonce | 832df765c8a8d2d80487764aa4465c415ae1822bd56ae9f4d2dec63ede9f8808 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzE0OjFFOTFGMjo2Q0YyQjI6NzA3QjJCOjZBNTIwMDI3IiwidmlzaXRvcl9pZCI6IjY4ODM4NjM2ODg0ODQzNTYxMzUiLCJyZWdpb25fZWRnZSI6InNlYSIsInJlZ2lvbl9yZW5kZXIiOiJzZWEifQ== |
| visitor-hmac | fdfb539e9efa4422c0e19c9b38c942f8d886e6e4b3c3b689d23a123303e9263e |
| hovercard-subject-tag | issue:857444750 |
| 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/19956/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1559d6a67cf4fa2ed6bc51c9decca5cc6833625372831e3b25191e21cb628a69/matplotlib/matplotlib/issues/19956 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1559d6a67cf4fa2ed6bc51c9decca5cc6833625372831e3b25191e21cb628a69/matplotlib/matplotlib/issues/19956 |
| og:image:alt | Problem Often, I will create figures using matplotlib using the Figure class explicitly, because either I want to make a figure and repeatedly tweak it to see how it looks, or I am creating a lot o... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | edmundsj |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width