Title: [Bug]: plt.bar legend displays incorrect style for empty data · Issue #21506 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: plt.bar legend displays incorrect style for empty data · Issue #21506 · matplotlib/matplotlib
X Title: [Bug]: plt.bar legend displays incorrect style for empty data · Issue #21506 · matplotlib/matplotlib
Description: Bug summary Legend items created from empty plt/ax.bar calls are displayed with the default style and the first color of the theme's cycle. This behavior contradicts the behavior of plt/ax.plot and plt/ax.scatter. Code for reproduction i...
Open Graph Description: Bug summary Legend items created from empty plt/ax.bar calls are displayed with the default style and the first color of the theme's cycle. This behavior contradicts the behavior of plt/ax.plot and...
X Description: Bug summary Legend items created from empty plt/ax.bar calls are displayed with the default style and the first color of the theme's cycle. This behavior contradicts the behavior of plt/ax.plot...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/21506
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: plt.bar legend displays incorrect style for empty data","articleBody":"### Bug summary\r\n\r\nLegend items created from empty `plt/ax.bar` calls are displayed with the default style and the first color of the theme's cycle. This behavior contradicts the behavior of `plt/ax.plot` and `plt/ax.scatter`.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\n# The bug happens with or without this import.\r\nimport numpy as np\r\n```\r\n\r\n```python\r\n# Actual outcome code\r\nplt.bar([], [], alpha=0.3, label=\"[], [], alpha=0.3\")\r\nplt.bar([], [], alpha=0.3, label=\"[], [], alpha=0.3\")\r\nplt.bar([np.nan], [np.nan], alpha=0.3, label=\"[np.nan], [np.nan], alpha=0.3\")\r\nplt.bar([], [], alpha=0.3, label=\"[], [], alpha=0.3\")\r\nplt.bar([1], [1], alpha=0.3, label=\"[1], [1], alpha=0.3\")\r\nplt.legend()\r\n```\r\n\r\n\r\n```python\r\n# Expected outcome code\r\nplt.plot([], [], alpha=0.5, label=\"[], [], alpha=0.5\")\r\nplt.plot([], [], alpha=0.5, label=\"[], [], alpha=0.5\")\r\nplt.plot([np.nan], [np.nan], alpha=0.5, label=\"[np.nan], [np.nan], alpha=0.5\")\r\nplt.plot([], [], alpha=0.5, label=\"[], [], alpha=0.5\")\r\nplt.plot([1], [1], alpha=0.5, label=\"[1], [1], alpha=0.5\")\r\nplt.legend()\r\n```\r\n\r\n### Actual outcome\r\n\r\nColor cycling and alpha are not respected for the `plt.bar([], [], ...)` calls.\r\n\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\nColor cycling and alpha are respected for the `plt.plot([], [], ...)` calls.\r\n\r\n\r\n\r\n\r\n### Operating system\r\n\r\nLinux\r\n\r\n### Matplotlib Version\r\n\r\n3.2.2\r\n\r\n### Matplotlib Backend\r\n\r\nmodule://ipykernel.pylab.backend_inline\r\n\r\n### Python version\r\n\r\n3.7.12 (default, Sep 10 2021, 00:21:48) [GCC 7.5.0]\r\n\r\n### Jupyter version\r\n\r\nColab\r\n\r\n### Other libraries\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\n_No response_\r\n\r\n### Conda channel\r\n\r\n_No response_","author":{"url":"https://github.com/phoenix-meadowlark","@type":"Person","name":"phoenix-meadowlark"},"datePublished":"2021-10-30T18:36:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/21506/matplotlib/issues/21506"}
| 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:c4ed75ef-b301-7541-af73-4de819953df4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3D0:2D331C:5A885F:7A7AF5:6A540F73 |
| html-safe-nonce | 2b038048624bc5893c5b7d11dce6f1ac80092baa1f304a1cdba430571c833cff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0QwOjJEMzMxQzo1QTg4NUY6N0E3QUY1OjZBNTQwRjczIiwidmlzaXRvcl9pZCI6IjUxOTg1MDU0OTA2MDMzMTUwNTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b6e15276a4aed0af8998f4253dc03b4dd656606a0ff656b6ec8378520011d5f7 |
| hovercard-subject-tag | issue:1040269246 |
| 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/21506/issue_layout |
| twitter:image | https://opengraph.githubassets.com/28153e37e4e550c30d99e7ebba4cdf9ff6fa40ef12dfb1d00b050eca9c0e2728/matplotlib/matplotlib/issues/21506 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/28153e37e4e550c30d99e7ebba4cdf9ff6fa40ef12dfb1d00b050eca9c0e2728/matplotlib/matplotlib/issues/21506 |
| og:image:alt | Bug summary Legend items created from empty plt/ax.bar calls are displayed with the default style and the first color of the theme's cycle. This behavior contradicts the behavior of plt/ax.plot and... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | phoenix-meadowlark |
| 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