Title: IndexError thrown by pyplot.legend() when plotting empty bar chart with label · Issue #13003 · matplotlib/matplotlib · GitHub
Open Graph Title: IndexError thrown by pyplot.legend() when plotting empty bar chart with label · Issue #13003 · matplotlib/matplotlib
X Title: IndexError thrown by pyplot.legend() when plotting empty bar chart with label · Issue #13003 · matplotlib/matplotlib
Description: Bug report Bug summary When I try to create bar chart with no data, and add a label to this chart, IndexError will be raised when trying to create legend for this plot Code for reproduction import matplotlib.pyplot as plt plt.bar([], [],...
Open Graph Description: Bug report Bug summary When I try to create bar chart with no data, and add a label to this chart, IndexError will be raised when trying to create legend for this plot Code for reproduction import ...
X Description: Bug report Bug summary When I try to create bar chart with no data, and add a label to this chart, IndexError will be raised when trying to create legend for this plot Code for reproduction import ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/13003
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"IndexError thrown by pyplot.legend() when plotting empty bar chart with label","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nWhen I try to create bar chart with no data, and add a label to this chart, IndexError will be raised when trying to create legend for this plot\r\n\r\n**Code for reproduction**\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nplt.bar([], [], label='foo')\r\nplt.legend()\r\n```\r\n\r\n**Actual outcome**\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"test.py\", line 3, in \u003cmodule\u003e\r\n plt.legend()\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/pyplot.py\", line 3823, in legend\r\n ret = gca().legend(*args, **kwargs)\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/axes/_axes.py\", line 557, in legend\r\n self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/legend.py\", line 699, in __init__\r\n self._init_legend_box(handles, labels, markerfirst)\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/legend.py\", line 954, in _init_legend_box\r\n fontsize, handlebox))\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/legend_handler.py\", line 119, in legend_artist\r\n fontsize, handlebox.get_transform())\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/legend_handler.py\", line 303, in create_artists\r\n self.update_prop(p, orig_handle, legend)\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/legend_handler.py\", line 76, in update_prop\r\n self._update_prop(legend_handle, orig_handle)\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/legend_handler.py\", line 69, in _update_prop\r\n self._update_prop_func(legend_handle, orig_handle)\r\n File \"/opt/conda/lib/python3.6/site-packages/matplotlib/legend_handler.py\", line 42, in update_from_first_child\r\n tgt.update_from(src.get_children()[0])\r\nIndexError: list index out of range\r\n```\r\n\r\n**Expected outcome**\r\n\r\n\u003c!--A description of the expected outcome from the code snippet--\u003e\r\n\u003c!--If this used to work in an earlier version of Matplotlib, please note the version it used to work on--\u003e\r\n\r\n**Matplotlib version**\r\n * Operating system: Linux 1f8cb2653e0b 4.14.85-1-MANJARO #1 SMP PREEMPT Sat Dec 1 12:18:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux\r\n * Matplotlib version: 3.0.2 (installed from PyPi)\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): module://backend_interagg\r\n * Python version: 3.6.7\r\n\r\n\r\n","author":{"url":"https://github.com/VanDavv","@type":"Person","name":"VanDavv"},"datePublished":"2018-12-17T13:46:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/13003/matplotlib/issues/13003"}
| 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:7c3c3b3d-34a6-1d31-764a-d378e120a384 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C890:A8D95:B463DF:F112F5:6A51A778 |
| html-safe-nonce | 1ea38f0fcdcc2dddd3437f548e5485e44b90f1ae7d7b088f3d2572ca676108a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODkwOkE4RDk1OkI0NjNERjpGMTEyRjU6NkE1MUE3NzgiLCJ2aXNpdG9yX2lkIjoiODgwODEzNzQzOTQzNDYxNDY0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c12b2e1a4427e43f9489f7292e10bb3abec058c0c23c33a253adaa36275c2bfd |
| hovercard-subject-tag | issue:391719392 |
| 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/13003/issue_layout |
| twitter:image | https://opengraph.githubassets.com/369d36fbfde8939bf56a3f267e8bc437e217f3c9e5afb634085fc2dcde34851c/matplotlib/matplotlib/issues/13003 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/369d36fbfde8939bf56a3f267e8bc437e217f3c9e5afb634085fc2dcde34851c/matplotlib/matplotlib/issues/13003 |
| og:image:alt | Bug report Bug summary When I try to create bar chart with no data, and add a label to this chart, IndexError will be raised when trying to create legend for this plot Code for reproduction import ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | VanDavv |
| 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