Title: [Bug]: stackplot creates artifacts when height of input is zero · Issue #22393 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: stackplot creates artifacts when height of input is zero · Issue #22393 · matplotlib/matplotlib
X Title: [Bug]: stackplot creates artifacts when height of input is zero · Issue #22393 · matplotlib/matplotlib
Description: Bug summary In some cases, when a given input for stackplot has zero value entries, thin lines are drawn. Code for reproduction import numpy as np import matplotlib.pyplot as plt np.random.seed(42) x = np.arange(10) y0 = np.linspace(0, 1...
Open Graph Description: Bug summary In some cases, when a given input for stackplot has zero value entries, thin lines are drawn. Code for reproduction import numpy as np import matplotlib.pyplot as plt np.random.seed(42)...
X Description: Bug summary In some cases, when a given input for stackplot has zero value entries, thin lines are drawn. Code for reproduction import numpy as np import matplotlib.pyplot as plt np.random.seed(42)...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22393
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: stackplot creates artifacts when height of input is zero","articleBody":"### Bug summary\n\nIn some cases, when a given input for `stackplot` has zero value entries, thin lines are drawn.\n\n### Code for reproduction\n\n```python\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\nnp.random.seed(42)\r\nx = np.arange(10)\r\ny0 = np.linspace(0, 1, 10)\r\ny1 = np.linspace(0, 1, 10)\r\ny2 = [0, 0, 0.25, 0, 0, 0, 0.25, 0, 0, 0]\r\ny3 = np.linspace(0, 1, 10)\r\n\r\n\r\ncolors=['grey', 'blue', 'red', 'blue']\r\n\r\ny = np.stack([y0, y1, y2, y3])\r\nim = plt.stackplot(x, y, colors=colors, lw=0)\n```\n\n\n### Actual outcome\n\n\r\n\r\nOne can see thin grey lines where the red object hast zero height.\n\n### Expected outcome\n\n\r\n\r\nThe thin lines are gone\n\n### Additional information\n\nThis only happens when the color above and below the empty data has the same color, but there are some use-cases where this is needed (see e.g. [fish plots for evolutionary relationships](https://i.stack.imgur.com/hNl5C.png)).\r\n\r\n\r\n# Fix\r\nThe individual calls to `fill_between` need to have the following parameters:\r\n`where=(stack[i, :] != stack[i+1, :])`, ` interpolate=True` and `edgecolor=color`.\r\n\r\nThese are the changes made to `matplotlib/lib/matplotlib/stackplot.py`\r\n```python\r\n # Color between x = 0 and the first array.\r\n color = ax._get_lines.get_next_color()\r\n coll = ax.fill_between(x, 0, stack[0, :],\r\n where=(stack[0, :] != 0), interpolate=True, edgecolor=color,\r\n facecolor=color, label=next(labels, None), **kwargs)\r\n coll.sticky_edges.y[:] = [0]\r\n r = [coll]\r\n\r\n # Color between array i-1 and array i\r\n for i in range(len(y) - 1):\r\n color = ax._get_lines.get_next_color()\r\n r.append(ax.fill_between(x, stack[i, :], stack[i+1, :], \r\n where=(stack[i, :] != stack[i+1, :]), interpolate=True, edgecolor=color,\r\n facecolor=color, label=next(labels, None), **kwargs))\r\n```\r\n\r\nThese changes get rid of the lines but as far as I tested it do not have side effects for other plots. Probably one should check whether edgecolor is set in `**kwargs` as well.\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n3.4.3\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nconda","author":{"url":"https://github.com/tlkaufmann","@type":"Person","name":"tlkaufmann"},"datePublished":"2022-02-04T12:52:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/22393/matplotlib/issues/22393"}
| 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:a1f5b7b4-b534-e256-0c86-7df5cc4ab276 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8FA0:378B6C:454833:5D0724:6A51C59D |
| html-safe-nonce | 67491f539396ce9cc2a746c175dcc2ade93008698f84c7adb6c43d5e8033d639 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkEwOjM3OEI2Qzo0NTQ4MzM6NUQwNzI0OjZBNTFDNTlEIiwidmlzaXRvcl9pZCI6IjI0MzEyODYyNTM5NTU2OTYwMjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | aefcbcf7f9b567dba2b5cc6375ba30e044355bccc523463e2865ec7482de9f72 |
| hovercard-subject-tag | issue:1124172555 |
| 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/22393/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1db2211384c3404ee1f7fdfeaac53be004c1a34ca345de38deaef5e5c95905d5/matplotlib/matplotlib/issues/22393 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1db2211384c3404ee1f7fdfeaac53be004c1a34ca345de38deaef5e5c95905d5/matplotlib/matplotlib/issues/22393 |
| og:image:alt | Bug summary In some cases, when a given input for stackplot has zero value entries, thin lines are drawn. Code for reproduction import numpy as np import matplotlib.pyplot as plt np.random.seed(42)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tlkaufmann |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width