Title: [ENH]: contour/tricontour: return values along contour · Issue #21309 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: contour/tricontour: return values along contour · Issue #21309 · matplotlib/matplotlib
X Title: [ENH]: contour/tricontour: return values along contour · Issue #21309 · matplotlib/matplotlib
Description: Problem (A follow-up on #20548.) The purpose of contour and tricontour is to draw contour lines along given levels. The algorithm tries to close the contour loops, but sometimes that's not possible or useful. Example: import numpy as np ...
Open Graph Description: Problem (A follow-up on #20548.) The purpose of contour and tricontour is to draw contour lines along given levels. The algorithm tries to close the contour loops, but sometimes that's not possible...
X Description: Problem (A follow-up on #20548.) The purpose of contour and tricontour is to draw contour lines along given levels. The algorithm tries to close the contour loops, but sometimes that's not poss...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/21309
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: contour/tricontour: return values along contour","articleBody":"### Problem\r\n\r\n(A follow-up on https://github.com/matplotlib/matplotlib/issues/20548.)\r\n\r\nThe purpose of contour and tricontour is to draw contour lines along given levels. The algorithm tries to close the contour loops, but sometimes that's not possible or useful. Example:\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\nxmin, xmax = -3.0, 3.0\r\nymin, ymax = -3.0, 3.0\r\nnx, ny = 500, 500\r\n\r\ndef f(z):\r\n return np.angle(z)\r\n\r\nx = np.linspace(xmin, xmax, nx)\r\ny = np.linspace(ymin, ymax, ny)\r\nX, Y = np.meshgrid(x, y)\r\nfZ = f(X + 1j * Y)\r\n\r\nc = plt.contour(X, Y, fZ, levels=[0.7853981633974483], colors=\"k\")\r\nplt.show()\r\n```\r\n\r\n\r\n\r\nThe left \"arm\" of the contour is wrong. Let's verify this by computing the values:\r\n```python\r\nfor allseg in c.allsegs:\r\n for seg in allseg:\r\n x, y = seg.T\r\n z = x + 1j * y\r\n print(f(z))\r\n```\r\n```python\r\n[3.14109133 3.14108931 3.14108728 3.14108523 3.14108316 3.14108107\r\n# ...\r\n 3.13344468 3.13287655 3.13222326 3.1314641 3.13057109 3.1295054\r\n 3.12821158 3.12660761 3.12456683 3.12188272 3.1181943 3.11280868\r\n 3.10420637 3.08829091 3.04901618 2.8198421 0.78539816 0.78539816\r\n 0.78539816 0.78539816 0.78539816 0.78539816 0.78539816 0.78539816\r\n 0.78539816 0.78539816 0.78539816 0.78539816 0.78539816 0.78539816\r\n# ...\r\n.78539816 0.78539816 0.78539816 0.78539816 0.78539816 0.78539816\r\n 0.78539816 0.78539816]\r\n```\r\nNote that the specified level is `0.7853981633974483`, so the first half is completely off. [A previous comment](https://github.com/matplotlib/matplotlib/issues/20548#issuecomment-871232335) suggests that the contouring algorithm is right, though.\r\n\r\nTo fix this, I manually set the corresponding segments to `np.nan` which prevents plotting. However, this does _not_ work for tricontour as I don't have a function `f()` that I can evaluate at the segments. The contouring algorithm itself must compute the values somewhere, so my suggestion would be to expose those values to the user.","author":{"url":"https://github.com/nschloe","@type":"Person","name":"nschloe"},"datePublished":"2021-10-07T14:13:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/21309/matplotlib/issues/21309"}
| 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:4bc28455-cf98-38a1-ba04-381828bc4fad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3C4:277ED1:9B44771:D14E12F:6A5E8694 |
| html-safe-nonce | 256f8232c9914cdadc4e3d240e6fc6f9265413de7eded4c1df848bf59ab3c219 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0M0OjI3N0VEMTo5QjQ0NzcxOkQxNEUxMkY6NkE1RTg2OTQiLCJ2aXNpdG9yX2lkIjoiNTg0ODQ2NzYyNDU2MTY0MTEwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fc25c04dd2f65eaacd2a74c869d2532f1ad4bb0f73f680c44b2f7e00ecc1b1d1 |
| hovercard-subject-tag | issue:1020095854 |
| 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/21309/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5467288a1e0e6a70e41f3da3d17dd80344795a54a708a86065f52b31d13def71/matplotlib/matplotlib/issues/21309 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5467288a1e0e6a70e41f3da3d17dd80344795a54a708a86065f52b31d13def71/matplotlib/matplotlib/issues/21309 |
| og:image:alt | Problem (A follow-up on #20548.) The purpose of contour and tricontour is to draw contour lines along given levels. The algorithm tries to close the contour loops, but sometimes that's not possible... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nschloe |
| hostname | github.com |
| expected-hostname | github.com |
| None | e0c30ec4bc4cc128be7eee7ef869507723a2ac9916267b7e0d370b3580a5e7ba |
| 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 | 68ef39d284f7f48d37e751bc9bc0a9a4166228d5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width