Title: Speeding up contours with (non-affine) transforms · Issue #11464 · matplotlib/matplotlib · GitHub
Open Graph Title: Speeding up contours with (non-affine) transforms · Issue #11464 · matplotlib/matplotlib
X Title: Speeding up contours with (non-affine) transforms · Issue #11464 · matplotlib/matplotlib
Description: For the Astropy project, we provide astronomy-specific transforms that users can use in various Matplotlib methods/artists, including e.g. Axes.contour. In fact, we have a sub-class of Axes called WCSAxes which until now just inherited t...
Open Graph Description: For the Astropy project, we provide astronomy-specific transforms that users can use in various Matplotlib methods/artists, including e.g. Axes.contour. In fact, we have a sub-class of Axes called ...
X Description: For the Astropy project, we provide astronomy-specific transforms that users can use in various Matplotlib methods/artists, including e.g. Axes.contour. In fact, we have a sub-class of Axes called ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/11464
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Speeding up contours with (non-affine) transforms","articleBody":"For the Astropy project, we provide astronomy-specific transforms that users can use in various Matplotlib methods/artists, including e.g. ``Axes.contour``. In fact, we have a sub-class of Axes called [WCSAxes](http://docs.astropy.org/en/stable/visualization/wcsaxes/index.html) which until now just inherited the default ``contour`` and ``contourf``. However, the complexity of the transforms means that there is a small overhead (\u003e1-10ms) for every call to the transform that is unrelated to the number of elements to transform.\r\n\r\nIn Matplotlib, when drawing contours with a transform:\r\n```\r\nax.contour(..., transform=...)\r\n```\r\neach individual path in the contour is passed to ``transform_path_non_affine``. This is done here:\r\n\r\nhttps://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/collections.py#L191\r\n\r\nHowever, this means that in cases where a contour map has say 1000 individual lines (not that uncommon with some astronomy images), drawing a contour map can take \u003e10s.\r\n\r\nI found a solution in astropy/astropy#7568 - override ``contour`` and call matplotlib's ``contour`` without the transform, then modify the vertices in-place afterwards by constructing a single array with all the vertices and transforming it in one go and splitting it up again. The key function is:\r\n\r\nhttps://github.com/astropy/astropy/pull/7568/files#diff-421f6873fdd2d8a90f39f3050534b0c3R139\r\n\r\nThis dramatically sped up drawing contours in our case. The reason I'm opening this issue (as suggested by @dopplershift on Gitter) is that this solution is not specific to Astropy. In fact, this could be copied almost as-is into Matplotlib if there was interest. In our case, there is basically no downside to doing this performance-wise even when there are very few contour lines, and I think this is generally true for this approach.\r\n\r\nFeel free to close this if you'd rather not port this over to Matplotlib though, as there may be subtleties I am not aware of!","author":{"url":"https://github.com/astrofrog","@type":"Person","name":"astrofrog"},"datePublished":"2018-06-20T18:56:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/11464/matplotlib/issues/11464"}
| 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:5ff583a4-d1b3-1181-91ed-e1c4f0198dca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E0B6:290D1F:29A317A:390165B:6A53C2DB |
| html-safe-nonce | 3c85e0bdbae53c7c1cb7e880f44a06b4fb2f899dc6bbab67c10fec8f745d7112 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEI2OjI5MEQxRjoyOUEzMTdBOjM5MDE2NUI6NkE1M0MyREIiLCJ2aXNpdG9yX2lkIjoiNjg0MDE3ODg4NDYyNzEyMDg1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a3785ba13566b12d6ee6e9ba35b6ce2ca5d1af185786a960267ac7a4d57f3b6b |
| hovercard-subject-tag | issue:334207741 |
| 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/11464/issue_layout |
| twitter:image | https://opengraph.githubassets.com/900f2a309a1f13dfd7a196b65ddd3aae590da6851c2617c1a911c5b1a6f4f14a/matplotlib/matplotlib/issues/11464 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/900f2a309a1f13dfd7a196b65ddd3aae590da6851c2617c1a911c5b1a6f4f14a/matplotlib/matplotlib/issues/11464 |
| og:image:alt | For the Astropy project, we provide astronomy-specific transforms that users can use in various Matplotlib methods/artists, including e.g. Axes.contour. In fact, we have a sub-class of Axes called ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | astrofrog |
| 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