Title: [ENH]: Multi hatching in `ax.stackplot()` · Issue #27146 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Multi hatching in `ax.stackplot()` · Issue #27146 · matplotlib/matplotlib
X Title: [ENH]: Multi hatching in `ax.stackplot()` · Issue #27146 · matplotlib/matplotlib
Description: Problem ax.stackplot() is used for conveniently plotting stacked area plot. The documentation says that any **kwargs is passed on to ax.fill_between. So, it all works fine if I work with colours, but not so much with hatching pattern. If...
Open Graph Description: Problem ax.stackplot() is used for conveniently plotting stacked area plot. The documentation says that any **kwargs is passed on to ax.fill_between. So, it all works fine if I work with colours, b...
X Description: Problem ax.stackplot() is used for conveniently plotting stacked area plot. The documentation says that any **kwargs is passed on to ax.fill_between. So, it all works fine if I work with colours, b...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27146
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Multi hatching in `ax.stackplot()`","articleBody":"### Problem\n\n`ax.stackplot()` is used for conveniently plotting stacked area plot.\r\n\r\nThe documentation says that any `**kwargs` is passed on to `ax.fill_between`.\r\n\r\nSo, it all works fine if I work with colours, but not so much with hatching pattern.\r\n\r\nIf I want to add hatching, this is what I get by default:\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\n# Data\r\ncols = 10\r\nrows = 4\r\n\r\ndata = (\r\n np.reshape(np.arange(0, cols, 1), (1, -1)) ** 2\r\n + np.reshape(np.arange(0, rows), (-1, 1))\r\n + np.random.random((rows, cols))*5\r\n)\r\n\r\n# Plot\r\nfig, ax = plt.subplots(\r\n figsize=(10,6),\r\n facecolor=\"white\",\r\n layout=\"constrained\"\r\n)\r\nfig.suptitle(\r\n \"with hatching\",\r\n fontsize=25,\r\n weight=\"bold\"\r\n)\r\n\r\nx = range(data.shape[1])\r\nax.stackplot(\r\n x, data,\r\n hatch=\"x\"\r\n)\r\n\r\nax.set_xlim(0, 9)\r\nax.set_ylim(0, 350)\r\n```\r\n\r\nThe outcome:\r\n\r\n\r\nBut I would be more interested in getting something like this:\r\n\r\n\r\n\n\n### Proposed solution\n\nThe calling signature would be the same as before with exception that the `hatch` parameter would accept e.g. a list with `hatching` styles you want to use.\r\n\r\nExample:\r\n```python\r\nax.stackplot(\r\n x, data,\r\n hatch=[\"x\", \"\\\\\", \".\", \"-\"]\r\n)\r\n```\r\n\r\nThe example I've used above in the problem was create using the code below and in this case it varies the hatching by the density:\r\n```python\r\nfig, ax = plt.subplots(\r\n figsize=(10,6),\r\n facecolor=\"white\",\r\n layout=\"constrained\"\r\n)\r\nfig.suptitle(\r\n \"with individual hatching\",\r\n fontsize=25,\r\n weight=\"bold\"\r\n)\r\n\r\nx = range(data.shape[1])\r\nstack_baseline = np.zeros((data.shape[1]))\r\nfor i, y in enumerate(data):\r\n ax.fill_between(\r\n x, stack_baseline, y+stack_baseline,\r\n facecolor=(1, 1, 1, 0),\r\n hatch=\"x\"*(data.shape[0]-i)\r\n )\r\n stack_baseline += y\r\n\r\nax.set_xlim(0, 9)\r\nax.set_ylim(0, 350)\r\n```\r\n\r\n","author":{"url":"https://github.com/pawjast","@type":"Person","name":"pawjast"},"datePublished":"2023-10-19T14:04:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/27146/matplotlib/issues/27146"}
| 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:46b9da25-2ead-adde-ed6e-cfe4f9f3023b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5FA:73358:1D413:279A8:6A50ED48 |
| html-safe-nonce | f9e3b538dff060493e1735721b7ab1c9f0c543df974658ed8f94c6e2fb6e0a71 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUZBOjczMzU4OjFENDEzOjI3OUE4OjZBNTBFRDQ4IiwidmlzaXRvcl9pZCI6IjEwNjA4MDk4NTk2NDQwNTg5NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0a88be40153a20a4aa9139a757282008dcc38c979fbd21ec53e04fa76792fe68 |
| hovercard-subject-tag | issue:1952351664 |
| 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/27146/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1f3c2152ce867f23bebc3c94a7fdf3df39f9752a7ccc0f0d21b13a7e19a8158c/matplotlib/matplotlib/issues/27146 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f3c2152ce867f23bebc3c94a7fdf3df39f9752a7ccc0f0d21b13a7e19a8158c/matplotlib/matplotlib/issues/27146 |
| og:image:alt | Problem ax.stackplot() is used for conveniently plotting stacked area plot. The documentation says that any **kwargs is passed on to ax.fill_between. So, it all works fine if I work with colours, b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pawjast |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 |
| 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 | 5ec60191a48933536a90c8a19f47142fcd0d4739 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width