Title: [Bug]: no longer able to set multiple hatch colors · Issue #28990 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: no longer able to set multiple hatch colors · Issue #28990 · matplotlib/matplotlib
X Title: [Bug]: no longer able to set multiple hatch colors · Issue #28990 · matplotlib/matplotlib
Description: Bug summary Possible bug or maybe a usage issue following some recent updates... In short, it used to be possible to set the hatch color for each filled contour area to a different color by iterating over the collections and then setting...
Open Graph Description: Bug summary Possible bug or maybe a usage issue following some recent updates... In short, it used to be possible to set the hatch color for each filled contour area to a different color by iterati...
X Description: Bug summary Possible bug or maybe a usage issue following some recent updates... In short, it used to be possible to set the hatch color for each filled contour area to a different color by iterati...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28990
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: no longer able to set multiple hatch colors","articleBody":"### Bug summary\n\nPossible bug or maybe a usage issue following some recent updates...\r\n\r\nIn short, it used to be possible to set the hatch color for each filled contour area to a different color by iterating over the collections and then setting the edgecolor for each, but that's no longer the case with Matplotlib 3.10 and the removal of collections. \r\n\r\nI've been trying to find a workaround after the recent updates, but am struggling a bit. Using `set_edgecolors` only sets a single hatch color for all filled contours (which seems unexpected based upon the docs and like a potential bug) and rcParams['hatch.color'] also just sets a single color (less suprising).\r\n\r\nIt's entirely possible I'm missing something here, but didn't see much in the docs to help either. \n\n### Code for reproduction\n\n```Python\n# The new approach I was hoping would work, but got unexpected results from\r\n\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\n# invent some numbers, turning the x and y arrays into simple\r\n# 2d arrays, which make combining them together easier.\r\nx = np.linspace(-3, 5, 150).reshape(1, -1)\r\ny = np.linspace(-3, 5, 120).reshape(-1, 1)\r\nz = np.cos(x) + np.sin(y)\r\n\r\n# we no longer need x and y to be 2 dimensional, so flatten them.\r\nx, y = x.flatten(), y.flatten()\r\n\r\nfig1, ax1 = plt.subplots()\r\ncs = ax1.contourf(x, y, z, hatches=['-', '/', '\\\\', '//'],\r\n cmap='gray', extend='both', alpha=0.5)\r\n\r\ncs.set_edgecolors([\"blue\",\"grey\",\"yellow\",\"red\"])\r\nfig1.colorbar(cs)\r\n\r\n\r\n\r\n# The older approach that now fails with Matplotlib 3.10\r\n\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\n# invent some numbers, turning the x and y arrays into simple\r\n# 2d arrays, which make combining them together easier.\r\nx = np.linspace(-3, 5, 150).reshape(1, -1)\r\ny = np.linspace(-3, 5, 120).reshape(-1, 1)\r\nz = np.cos(x) + np.sin(y)\r\n\r\n# we no longer need x and y to be 2 dimensional, so flatten them.\r\nx, y = x.flatten(), y.flatten()\r\n\r\nfig1, ax1 = plt.subplots()\r\ncs = ax1.contourf(x, y, z, hatches=['-', '/', '\\\\', '//'],\r\n cmap='gray', extend='both', alpha=0.5)\r\n\r\ncolors = [\"blue\",\"grey\",\"yellow\",\"red\"]\r\nfor i, collection in enumerate(cs.collections):\r\n collection.set_edgecolor(colors[i % len(colors)])\r\nfig1.colorbar(cs)\n```\n\n\n### Actual outcome\n\n\u003cimg width=\"581\" alt=\"Screen Shot 2024-10-17 at 4 19 18 PM\" src=\"https://github.com/user-attachments/assets/6c2306b5-196b-4488-b02d-2175df0f3238\"\u003e\r\n\n\n### Expected outcome\n\n\u003cimg width=\"589\" alt=\"Screen Shot 2024-10-17 at 4 18 22 PM\" src=\"https://github.com/user-attachments/assets/705fc1c6-7e35-46c8-a815-5e3f57458b0a\"\u003e\r\n\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nOS/X\n\n### Matplotlib Version\n\n3.9.2\n\n### Matplotlib Backend\n\n'module://matplotlib_inline.backend_inline'\n\n### Python version\n\n3.11.7\n\n### Jupyter version\n\n4.0.9\n\n### Installation\n\nconda","author":{"url":"https://github.com/kafitzgerald","@type":"Person","name":"kafitzgerald"},"datePublished":"2024-10-17T22:21:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/28990/matplotlib/issues/28990"}
| 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:a0349adc-248d-7e3d-0731-d9116512adc5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A858:101A9F:D9B195:12163A4:6A532B77 |
| html-safe-nonce | 4b20953f5f6f702c58d481c42620790071751f681f84deb191b6d9200e527665 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODU4OjEwMUE5RjpEOUIxOTU6MTIxNjNBNDo2QTUzMkI3NyIsInZpc2l0b3JfaWQiOiIxNzQ0MTY5NTcyMjcwODQ2NjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f3927a27b11942b188514507029ad2ba6803aad206331f85dc8fe7e18e132afd |
| hovercard-subject-tag | issue:2595871298 |
| 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/28990/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b3d81270f55103cc770941952a359867d1a9757a57bc803ba477345002911581/matplotlib/matplotlib/issues/28990 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b3d81270f55103cc770941952a359867d1a9757a57bc803ba477345002911581/matplotlib/matplotlib/issues/28990 |
| og:image:alt | Bug summary Possible bug or maybe a usage issue following some recent updates... In short, it used to be possible to set the hatch color for each filled contour area to a different color by iterati... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kafitzgerald |
| 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