René's URL Explorer Experiment


Title: [Doc]: Improving the pcolor(mesh) documentation: how NOT TO plot some data · Issue #21043 · matplotlib/matplotlib · GitHub

Open Graph Title: [Doc]: Improving the pcolor(mesh) documentation: how NOT TO plot some data · Issue #21043 · matplotlib/matplotlib

X Title: [Doc]: Improving the pcolor(mesh) documentation: how NOT TO plot some data · Issue #21043 · matplotlib/matplotlib

Description: Documentation Link https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html Problem [ The following can possibly also apply to pcolor or similar graphics ] pcolormesh is very useful when you need to look pr...

Open Graph Description: Documentation Link https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html Problem [ The following can possibly also apply to pcolor or similar graphics ] pcolormesh...

X Description: Documentation Link https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html Problem [ The following can possibly also apply to pcolor or similar graphics ] pcolormesh...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Doc]: Improving the pcolor(mesh) documentation: how NOT TO plot some data","articleBody":"### Documentation Link\n\nhttps://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html\n\n### Problem\n\n[ _The following can possibly also apply to pcolor or similar graphics_ ]\r\n\r\n`pcolormesh` is very useful when you need to **look precisely at the values of a 2D data field** (rather than using `contour` and `contourf` and wondering how the contours are computed):\r\n- If you want to pinpoint the **locations of specific values**, you need to use only a few specific colors, using `ListedColormap`.\r\n- And if you want to look at the **locations of only one value** (e.g. the location of a data mask), you need to plot only the values in **one** interval and **completely ignore the other values**\r\n\r\nThe [pcolormesh example page](https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html) unfortunately does not cover the use cases mentioned above:\r\n- no example using `ListedColormap`\r\n- no mention that the **data will be plotted even if it lies outside the requested levels**, using the first and last specified colors! This is so misleading that it's almost more a bug than a feature! This is probably obvious for the matplotlib colormaps and norm gurus, but not for most people. I end up having to read again all the color documentation each time I come back to matplotlib\r\n- no mention that you have to explicitly **specify a transparent (`alpha=0`) color** using `set_bad`, `set_over` and `set_under` for **removing what should not be plotted**. Maybe there is a cleaner (more obvious) way to do that. I will be glad to learn that (from an improved documentation)\r\n- no mention that a workaround is to use `numpy.ma` to **mask the values that should not be plotted**. But this may be tricky for people who are not used to dealing with cleanly masked/missing values\n\n### Suggested improvement\n\nThe following code and output image, based on the [Making levels using Norms](https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html#making-levels-using-norms) example tentatively shows what is missing (in my opinion) in the documentation, as described above\r\n\r\nIt can hopefully be used to improve/extend the documentation\r\n```\r\n#!/usr/bin/env python\r\n\r\n# pcolormesh test/example adapted from\r\n# https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html#making-levels-using-norms\r\n\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.colors import ListedColormap, BoundaryNorm\r\nfrom matplotlib.ticker import MaxNLocator\r\nimport numpy as np\r\n\r\n# make these smaller to increase the resolution\r\ndx, dy = 0.05, 0.05\r\n\r\n# generate 2 2d grids for the x \u0026 y bounds\r\ny, x = np.mgrid[slice(1, 5 + dy, dy),\r\n                slice(1, 5 + dx, dx)]\r\n\r\nz = np.sin(x)**10 + np.cos(10 + y*x) * np.cos(x)\r\n\r\n# x and y are bounds, so z should be the value *inside* those bounds.\r\n# Therefore, remove the last value from the z array.\r\nz = z[:-1, :-1]\r\n\r\n\r\n# pick the desired colormap, sensible levels, and define a normalization\r\n# instance which takes data values and translates those into levels.\r\ncmap_0 = plt.get_cmap('PiYG')\r\nlevels_0 = MaxNLocator(nbins=15).tick_values(z.min(), z.max())\r\nnorm_0 = BoundaryNorm(levels_0, ncolors=cmap_0.N, clip=True)\r\n\r\nfig, (ax_0, ax_1, ax_2, ax_3, ax_4, ax_5) = plt.subplots(nrows=6)\r\nfig.set_size_inches(5, 12)\r\n\r\nim_0 = ax_0.pcolormesh(x, y, z, cmap=cmap_0, norm=norm_0)\r\nfig.colorbar(im_0, ax=ax_0)\r\nax_0.set_title('pcolormesh with levels')\r\n\r\n\r\nax_1.set_title('3 intervals/colors covering the\\nfull data range ([%.3f, %.3f])' % (z.min(), z.max()))\r\n\r\ncmap_1 = ListedColormap(['pink', 'lavender', 'green'])\r\nlevels_1 = [-1.1, -0.3, 0.3, 1.1]\r\nnorm_1 = BoundaryNorm(levels_1, cmap_1.N)\r\n\r\nim_1 = ax_1.pcolormesh(x, y, z,\r\n                       cmap=cmap_1, norm=norm_1,\r\n                       zorder=20)\r\nfig.colorbar(im_1, ax=ax_1)\r\n\r\n\r\nax_2.set_title('Top of data range is above the color scale\\n...but set_over color is NOT specified')\r\n\r\ncmap_2 = ListedColormap(['pink', 'lavender'])\r\nlevels_2 = [-1.1, -0.3, 0.3]\r\nnorm_2 = BoundaryNorm(levels_2, cmap_2.N)\r\n\r\nim_2 = ax_2.pcolormesh(x, y, z,\r\n                       cmap=cmap_2, norm=norm_2,\r\n                     zorder=20)\r\nfig.colorbar(im_2, ax=ax_2)\r\n\r\n\r\nax_3.set_title('BLUE color specified for\\ndata ABOVE the color scale')\r\n\r\ncmap_3 = ListedColormap(['pink', 'lavender'])\r\ncmap_3.set_over('blue')\r\nlevels_3 = [-1.1, -0.3, 0.3]\r\nnorm_3 = BoundaryNorm(levels_3, cmap_3.N)\r\n\r\nim_3 = ax_3.pcolormesh(x, y, z,\r\n                       cmap=cmap_3, norm=norm_3,\r\n                       zorder=20)\r\ntext_3 = ax_3.text(0.05, 0.3, 'Test text\\nin the BACKGROUND',\r\n                   fontsize='xx-large',\r\n                   horizontalalignment='left',\r\n                   verticalalignment='center', transform=ax_3.transAxes,\r\n                   zorder=10)\r\nfig.colorbar(im_3, ax=ax_3)\r\n\r\n\r\nax_4.set_title('Color above the scale is now\\nfully TRANSPARENT (alpha=0)')\r\n\r\ncmap_4 = ListedColormap(['pink', 'lavender'])\r\ncmap_4.set_over('black', alpha=0)\r\nlevels_4 = [-1.1, -0.3, 0.3]\r\nnorm_4 = BoundaryNorm(levels_4, cmap_4.N)\r\n\r\nim_4 = ax_4.pcolormesh(x, y, z,\r\n                       cmap=cmap_4, norm=norm_4,\r\n                       zorder=20)\r\ntext_4 = ax_4.text(0.05, 0.3, 'Test text\\nin the BACKGROUND',\r\n                   fontsize='xx-large',\r\n                   horizontalalignment='left',\r\n                   verticalalignment='center', transform=ax_4.transAxes,\r\n                   zorder=10)\r\nfig.colorbar(im_4, ax=ax_4)\r\n\r\n\r\nax_5.set_title('Color above the scale is NOT TRANSPARENT\\n...but the data above 0. is MASKED')\r\n\r\n# MASK the values we do not want, instead of plotting them with a\r\n# fully transparent color\r\nzm = np.ma.masked_greater(z, 0.)\r\n\r\ncmap_5 = ListedColormap(['pink', 'lavender'])\r\n# For testing purpose, we explicitly specify a fully opaque color\r\n# (but opaque is the default anyway)\r\ncmap_5.set_over('black', alpha=1)\r\nlevels_5 = [-1.1, -0.3, 0.3]\r\nnorm_5 = BoundaryNorm(levels_5, cmap_5.N)\r\n\r\nim_5 = ax_5.pcolormesh(x, y, zm,\r\n                       cmap=cmap_5, norm=norm_5,\r\n                       zorder=20)\r\ntext_5 = ax_5.text(0.05, 0.3, 'Test text\\nin the BACKGROUND',\r\n                   fontsize='xx-large',\r\n                   horizontalalignment='left',\r\n                   verticalalignment='center', transform=ax_5.transAxes,\r\n                   zorder=10)\r\nfig.colorbar(im_5, ax=ax_5)\r\n\r\n\r\n# adjust spacing between subplots so `ax1` title and `ax0` tick labels\r\n# don't overlap\r\nfig.tight_layout()\r\n\r\nfig.savefig('test_pcolormesh.png')\r\n\r\nplt.show()\r\n```\r\n![test_pcolormesh](https://user-images.githubusercontent.com/2785573/132951175-5314bd0b-5e85-4b70-8355-52ccbd300987.png)\r\n\n\n### Matplotlib Version\n\n3.3.4\n\n### Matplotlib documentation version\n\n3.4.3","author":{"url":"https://github.com/jypeter","@type":"Person","name":"jypeter"},"datePublished":"2021-09-11T14:37:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/21043/matplotlib/issues/21043"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:5285b8f0-9489-135e-9772-45bb78fa5b55
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDE3A:1CCBDE:221BD25:2E8D873:6A539435
html-safe-nonce6abfcf9e4de2e3959e99a2de5973beefd5bdbd35a2c3d13a6cd9b093d88a47cb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTNBOjFDQ0JERToyMjFCRDI1OjJFOEQ4NzM6NkE1Mzk0MzUiLCJ2aXNpdG9yX2lkIjoiODY3NTQxNjM5MTU3MzI3OTc5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb587ec8397ad53339896ce9a1ce070988f03a5d6f69d4a5ff55e0bc4fd461c38
hovercard-subject-tagissue:993856218
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/21043/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ee6ba910bb9d1b233f2afa6feaff37c8999da9e81890df890908ac035371b520/matplotlib/matplotlib/issues/21043
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ee6ba910bb9d1b233f2afa6feaff37c8999da9e81890df890908ac035371b520/matplotlib/matplotlib/issues/21043
og:image:altDocumentation Link https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html Problem [ The following can possibly also apply to pcolor or similar graphics ] pcolormesh...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejypeter
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-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/21043#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F21043
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%2F21043
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/21043
Reloadhttps://github.com/matplotlib/matplotlib/issues/21043
Reloadhttps://github.com/matplotlib/matplotlib/issues/21043
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/21043
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/21043
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
[Doc]: Improving the pcolor(mesh) documentation: how NOT TO plot some datahttps://github.com/matplotlib/matplotlib/issues/21043#top
Documentationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Documentation%22
status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.https://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22status%3A%20closed%20as%20inactive%22
status: inactiveMarked by the “Stale” Github Actionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22status%3A%20inactive%22
https://github.com/jypeter
jypeterhttps://github.com/jypeter
on Sep 11, 2021https://github.com/matplotlib/matplotlib/issues/21043#issue-993856218
https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.htmlhttps://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html
pcolormesh example pagehttps://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html
Making levels using Normshttps://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_levels.html#making-levels-using-norms
https://user-images.githubusercontent.com/2785573/132951175-5314bd0b-5e85-4b70-8355-52ccbd300987.png
Documentationhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22Documentation%22
status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.https://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22status%3A%20closed%20as%20inactive%22
status: inactiveMarked by the “Stale” Github Actionhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22status%3A%20inactive%22
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.