Title: v3.3.0 breaks sca(ax) · Issue #19380 · matplotlib/matplotlib · GitHub
Open Graph Title: v3.3.0 breaks sca(ax) · Issue #19380 · matplotlib/matplotlib
X Title: v3.3.0 breaks sca(ax) · Issue #19380 · matplotlib/matplotlib
Description: Hi, I encountered an error calling sca(ax) together with usage of FigureCanvasTkAgg(). Following would be a simple sequence illustrating the problem. // Note that plt.gca().figure == figure ... = FigureCanvasTkAgg(figure, ...) plt.sca(pl...
Open Graph Description: Hi, I encountered an error calling sca(ax) together with usage of FigureCanvasTkAgg(). Following would be a simple sequence illustrating the problem. // Note that plt.gca().figure == figure ... = F...
X Description: Hi, I encountered an error calling sca(ax) together with usage of FigureCanvasTkAgg(). Following would be a simple sequence illustrating the problem. // Note that plt.gca().figure == figure ... = F...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/19380
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"v3.3.0 breaks sca(ax)","articleBody":"Hi,\r\n\r\nI encountered an error calling sca(ax) together with usage of FigureCanvasTkAgg(). Following would be a simple sequence illustrating the problem.\r\n```\r\n // Note that plt.gca().figure == figure\r\n... = FigureCanvasTkAgg(figure, ...)\r\nplt.sca(plt.gca())\r\n```\r\nThe problem is because FigureCanvasTkAgg(...) will call FigureCanvasBase.__init__(...) which resets the manager field needed in sca(). Below are the listing showing the problem:\r\n```\r\nclass FigureCanvasBase:\r\n def __init__(self, figure):\r\n ...\r\n figure.set_canvas(self)\r\n self.figure = figure\r\n **# Here it is setting canvas.manager to None!!**\r\n self.manager = None\r\n ...\r\n\r\ndef sca(ax):\r\n \"\"\"\r\n Set the current Axes to *ax* and the current Figure to the parent of *ax*.\r\n \"\"\"\r\n if not hasattr(ax.figure.canvas, \"manager\"):\r\n raise ValueError(\"Axes parent figure is not managed by pyplot\")\r\n **# !!! ax.figure.canvas.manager is None!**\r\n _pylab_helpers.Gcf.set_active(ax.figure.canvas.manager)\r\n ax.figure.sca(ax)\r\n```\r\n\r\nFor workaround, I checked out old version of sca(ax) from 3.2.2 and it seems to be working. On the other hand, I am not sure whether the old version is robust in v3.3.0 despite of this working situation.\r\n```\r\ndef sca(ax):\r\n \"\"\"\r\n Set the current Axes instance to *ax*.\r\n\r\n The current Figure is updated to the parent of *ax*.\r\n \"\"\"\r\n managers = _pylab_helpers.Gcf.get_all_fig_managers()\r\n for m in managers:\r\n if ax in m.canvas.figure.axes:\r\n _pylab_helpers.Gcf.set_active(m)\r\n m.canvas.figure.sca(ax)\r\n return\r\n raise ValueError(\"Axes instance argument was not found in a figure\")\r\n```\r\nPlease check and see whether bring back of old version of sca(ax) is a correct fix of this issue.\r\n","author":{"url":"https://github.com/david-c-wong","@type":"Person","name":"david-c-wong"},"datePublished":"2021-01-27T21:55:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/19380/matplotlib/issues/19380"}
| 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:2fef89e8-838b-a46e-9bda-73f79ac57e36 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3E4:276C72:332BD85:45B7808:6A53F00F |
| html-safe-nonce | aa81a4d809bbc70f2adb426ee45db8cc26394358ce3a27c737090ef48d5a7965 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0U0OjI3NkM3MjozMzJCRDg1OjQ1Qjc4MDg6NkE1M0YwMEYiLCJ2aXNpdG9yX2lkIjoiMTg5NDUzMTUyMzk5MTI2NTQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c1638bca7d64e8bb8415cdec1c8de74467b63b0e74dabf8e5a663cb98c0afd93 |
| hovercard-subject-tag | issue:795476086 |
| 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/19380/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6b8d95480af4b73af04d394f6299dc43d2dbda3069c499f446bfda6536977231/matplotlib/matplotlib/issues/19380 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6b8d95480af4b73af04d394f6299dc43d2dbda3069c499f446bfda6536977231/matplotlib/matplotlib/issues/19380 |
| og:image:alt | Hi, I encountered an error calling sca(ax) together with usage of FigureCanvasTkAgg(). Following would be a simple sequence illustrating the problem. // Note that plt.gca().figure == figure ... = F... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | david-c-wong |
| 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