René's URL Explorer Experiment


Title: [Bug]: matplotlib.path.Path.to_polygons fails with TriContourSet paths · Issue #25114 · matplotlib/matplotlib · GitHub

Open Graph Title: [Bug]: matplotlib.path.Path.to_polygons fails with TriContourSet paths · Issue #25114 · matplotlib/matplotlib

X Title: [Bug]: matplotlib.path.Path.to_polygons fails with TriContourSet paths · Issue #25114 · matplotlib/matplotlib

Description: Bug summary The Path objects produced by tricontourf to draw its contours lead to spurious polygons when running the respective to_polygons method. Code for reproduction import numpy as np import matplotlib as mpl import matplotlib.pyplo...

Open Graph Description: Bug summary The Path objects produced by tricontourf to draw its contours lead to spurious polygons when running the respective to_polygons method. Code for reproduction import numpy as np import m...

X Description: Bug summary The Path objects produced by tricontourf to draw its contours lead to spurious polygons when running the respective to_polygons method. Code for reproduction import numpy as np import m...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/25114

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: matplotlib.path.Path.to_polygons fails with TriContourSet paths","articleBody":"### Bug summary\n\nThe [Path](https://matplotlib.org/stable/api/path_api.html#matplotlib.path.Path) objects produced by [tricontourf](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tricontourf.html) to draw its contours lead to spurious polygons when running the respective `to_polygons` method.\r\n\n\n### Code for reproduction\n\n```python\nimport numpy as np\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.tri\r\n\r\n# Example for TriContour based from:\r\n# https://matplotlib.org/2.0.2/examples/pylab_examples/tricontour_smooth_delaunay.html\r\n\r\n\r\ndef experiment_res(x, y):\r\n    \"\"\" An analytic function representing experiment results \"\"\"\r\n    x = 2.*x\r\n    r1 = np.sqrt((0.5 - x)**2 + (0.5 - y)**2)\r\n    theta1 = np.arctan2(0.5 - x, 0.5 - y)\r\n    r2 = np.sqrt((-x - 0.2)**2 + (-y - 0.2)**2)\r\n    theta2 = np.arctan2(-x - 0.2, -y - 0.2)\r\n    z = (4*(np.exp((r1/10)**2) - 1)*30. * np.cos(3*theta1) +\r\n         (np.exp((r2/10)**2) - 1)*30. * np.cos(5*theta2) +\r\n         2*(x**2 + y**2))\r\n    return (np.max(z) - z)/(np.max(z) - np.min(z))\r\n\r\nn = 200\r\nrandom_gen = np.random.mtrand.RandomState(seed=127260)\r\nx = random_gen.uniform(-1., 1., size=n)\r\ny = random_gen.uniform(-1., 1., size=n)\r\nv = experiment_res(x, y)\r\n\r\n## triangulate\r\ntri = mpl.tri.Triangulation(x, y)\r\nmask = mpl.tri.TriAnalyzer(tri).get_flat_tri_mask(min_circle_ratio=.01)\r\ntri.set_mask(mask)\r\n\r\n## refine triangular mesh\r\nrefiner = mpl.tri.UniformTriRefiner(tri)\r\ntriFiner, vFiner = refiner.refine_field(v, subdiv=2)  # uses CubicTriInterpolator\r\n\r\n## plot the mesh\r\nplt.close('all')\r\nplt.triplot(tri, color='k', lw=.8)\r\nplt.triplot(triFiner, color='k', alpha=.3, lw=.5)\r\nplt.show()\r\n\r\n## plot and create TriCounterSet object\r\nlevels = [.7, .9, 1]\r\ncmap = mpl.cm.plasma\r\nplt.close('all')\r\ncl = plt.tricontour(triFiner, vFiner, levels=levels, colors='k', linewidths=2, linestyles='--')\r\ncf = plt.tricontourf(triFiner, vFiner, levels=levels, cmap=cmap, extend='both', alpha=.8)\r\n_ = [collection.set_edgecolor(\"face\") for collection in cf.collections]  # https://stackoverflow.com/a/73805556/921580\r\nplt.triplot(tri, color='k', lw=1.5, alpha=.1)  # refined mesh\r\nplt.triplot(triFiner, color='k', lw=.5, alpha=.1)  # original mesh\r\ncb = plt.colorbar(cf)\r\nplt.show()\r\n\r\n## retrieve contours from TriContourSet (paths) and convert to polygons\r\nfor i in range(len(cf.collections)):\r\n    plt.gca().set_xlim(-1.1, 1.1)\r\n    plt.gca().set_ylim(-1.1, 1.1)\r\n    [plt.gca().add_patch(\r\n            mpl.patches.PathPatch(\r\n                cf.collections[i].get_paths()[j],\r\n                facecolor=cf.collections[i].get_facecolor()\r\n            )\r\n        ) for j in range(len(cf.collections[i].get_paths()))]\r\n    [plt.plot(*list(zip(*p)), c='red', ls='--') \r\n            for path in cf.collections[i].get_paths()\r\n            for p in path.to_polygons()\r\n        ]\r\n    if i == (len(cf.collections) - 2):\r\n        plt.savefig('bug_actual_outcome.png')\r\n    plt.show()\r\n\r\n## compare path vertices with output from to_polygons method\r\npath = cf.collections[-2].get_paths()[0]\r\nprint(\"\\npath vertices and codes:\\n\", path)\r\nprint(\"\\npath.to_polygons() = \\n\", path.to_polygons())\n```\n\n\n### Actual outcome\n\n![bug_actual_outcome](https://user-images.githubusercontent.com/1119116/215825498-d59e4fbc-a439-448d-bfff-e9c27b07b8f8.png)\n\n### Expected outcome\n\n![bug_expected_outcome](https://user-images.githubusercontent.com/1119116/215825869-a279a2e5-d19f-47ca-b6af-1741b503b7a5.png)\r\n\n\n### Additional information\n\nThe issue seems to be related to the [Path](https://matplotlib.org/stable/api/path_api.html#matplotlib.path.Path) object and its `to_polygons` method. More specifically the problem may happen when a Path contains multiple polylines but is defined without the `CLOSEPOLY` codes ending each polyline. When producing contour plots the code can cope with this data without problems, but the `to_polygons` method cannot.\r\n\r\nI have tested in both 3.4.1 and 3.0.2 versions and both have the same problem.\r\n\r\nI have a fix where I defined a function `path2polygons`:\r\n\r\n```python\r\ndef path2polygons(path):\r\n    assert isinstance(path, mpl.path.Path), f\"Type of input is {type(path)} instead of Path.\"\r\n    codesOld = path.codes[path.codes != mpl.path.Path.CLOSEPOLY]\r\n    vertsOld = path.vertices[path.codes != mpl.path.Path.CLOSEPOLY]\r\n    jj = np.append(np.flatnonzero(codesOld == path.MOVETO), [len(codesOld)])\r\n    verts, codes = [], []\r\n    for ji, je in zip(jj[:-1], jj[1:]):\r\n        codes.extend(   [mpl.path.Path.MOVETO]\r\n                      + [mpl.path.Path.LINETO]*(je - ji - 1)\r\n                      + [mpl.path.Path.CLOSEPOLY]\r\n                    )\r\n        verts.extend( list(vertsOld[ji:je]) + [vertsOld[ji]] )\r\n    return mpl.path.Path(verts, codes).to_polygons()\r\n```\r\nbut is not tested with other Path codes such as `CURVE3` and `CURVE4`.\r\n\n\n### Operating system\n\nDebian 10\n\n### Matplotlib Version\n\n3.4.1\n\n### Matplotlib Backend\n\nTkAgg\n\n### Python version\n\n3.7.3\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/cvr","@type":"Person","name":"cvr"},"datePublished":"2023-01-31T17:00:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/25114/matplotlib/issues/25114"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:36e9ebd8-1c06-c9f8-0fbf-77d213d358bc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE5D6:399A66:CCC47B:1178F3D:6A53A60F
html-safe-nonce802442d25146bee7d4830bf211b26b33d2e53013f71d4be1b8880563b61e3a7e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUQ2OjM5OUE2NjpDQ0M0N0I6MTE3OEYzRDo2QTUzQTYwRiIsInZpc2l0b3JfaWQiOiIzMzE4NTIxODcxOTA2MDg4NDYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac9389464dd77a0c58b6eff2faa6cf4ec7a2739d9e4f483a70f12f22ff7e668402
hovercard-subject-tagissue:1564688938
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/25114/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8048cc2715f1a3bfc56c8d699e209d4ccf828c4f92f35cc0fd7a36a74542af18/matplotlib/matplotlib/issues/25114
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8048cc2715f1a3bfc56c8d699e209d4ccf828c4f92f35cc0fd7a36a74542af18/matplotlib/matplotlib/issues/25114
og:image:altBug summary The Path objects produced by tricontourf to draw its contours lead to spurious polygons when running the respective to_polygons method. Code for reproduction import numpy as np import m...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecvr
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/25114#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F25114
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F25114
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/25114
Reloadhttps://github.com/matplotlib/matplotlib/issues/25114
Reloadhttps://github.com/matplotlib/matplotlib/issues/25114
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/25114
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/25114
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 408 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
#26226https://github.com/matplotlib/matplotlib/pull/26226
[Bug]: matplotlib.path.Path.to_polygons fails with TriContourSet pathshttps://github.com/matplotlib/matplotlib/issues/25114#top
#26226https://github.com/matplotlib/matplotlib/pull/26226
v3.8.0https://github.com/matplotlib/matplotlib/milestone/77
https://github.com/cvr
cvrhttps://github.com/cvr
on Jan 31, 2023https://github.com/matplotlib/matplotlib/issues/25114#issue-1564688938
Pathhttps://matplotlib.org/stable/api/path_api.html#matplotlib.path.Path
tricontourfhttps://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tricontourf.html
https://user-images.githubusercontent.com/1119116/215825498-d59e4fbc-a439-448d-bfff-e9c27b07b8f8.png
https://user-images.githubusercontent.com/1119116/215825869-a279a2e5-d19f-47ca-b6af-1741b503b7a5.png
Pathhttps://matplotlib.org/stable/api/path_api.html#matplotlib.path.Path
v3.8.0https://github.com/matplotlib/matplotlib/milestone/77
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.