Title: [Bug]: Legend kwarg `labelcolor='linecolor'` not working properly when `facecolor` is `'None'` · Issue #30298 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Legend kwarg `labelcolor='linecolor'` not working properly when `facecolor` is `'None'` · Issue #30298 · matplotlib/matplotlib
X Title: [Bug]: Legend kwarg `labelcolor='linecolor'` not working properly when `facecolor` is `'None'` · Issue #30298 · matplotlib/matplotlib
Description: Bug summary The legend kwarg labelcolor='linecolor' does not play nicely with histtype='step' histograms or with fc='None' scatter plots, resulting in an invisible legend label for the histogram, and in an IndexError for the scatter plot...
Open Graph Description: Bug summary The legend kwarg labelcolor='linecolor' does not play nicely with histtype='step' histograms or with fc='None' scatter plots, resulting in an invisible legend label for the histogram, a...
X Description: Bug summary The legend kwarg labelcolor='linecolor' does not play nicely with histtype='step' histograms or with fc='None' scatter plots, resulting in an invisible legend la...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30298
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Legend kwarg `labelcolor='linecolor'` not working properly when `facecolor` is `'None'` ","articleBody":"### Bug summary\n\nThe legend kwarg `labelcolor='linecolor'` does not play nicely with `histtype='step'` histograms or with `fc='None'` scatter plots, resulting in an invisible legend label for the histogram, and in an IndexError for the scatter plot.\n\n### Code for reproduction\n\n```Python\nimport numpy as np\nimport matplotlib.pyplot as plt\nplt.rcParams['figure.figsize'] = (5, 5)\nplt.rcParams['legend.loc'] = 1\nplt.rcParams['legend.framealpha'] = 1\n\nx, y = np.random.randn(2, 1000)\n\nfig, axes = plt.subplots(2, 2, sharex=True, sharey='row')\naxes[0, 0].hist(x, histtype='bar', label=\"spam\")\naxes[0, 1].hist(x, histtype='step', label=\"spam\")\naxes[1, 0].scatter(x, y, label=\"spam\")\naxes[1, 1].scatter(x, y, ec='C0', fc='None', label=\"spam\")\nfor ax in axes.ravel():\n ax.legend(labelcolor='linecolor')\n```\n\n### Actual outcome\n\n\u003cimg width=\"443\" height=\"428\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/6f528aac-fa42-456d-ad4a-4aeb3063ac62\" /\u003e\n\nNote:\n* correctly coloured legend labels in both left panels \n* invisible legend label in the top right panel\n* no legend for the bottom right panel, instead the following error message:\n\n```\n---------------------------------------------------------------------------\nIndexError Traceback (most recent call last)\nCell In[1], line 15\n 13 axes[1, 1].scatter(x, y, ec='C0', fc='None', label=\"spam\")\n 14 for ax in axes.ravel():\n---\u003e 15 ax.legend(labelcolor='linecolor')\n\nFile [~/.virtualenv/py3121env/lib/python3.12/site-packages/matplotlib/axes/_axes.py:337](http://localhost:8888/home/lukas/.virtualenv/py3121env/lib/python3.12/site-packages/matplotlib/axes/_axes.py#line=336), in Axes.legend(self, *args, **kwargs)\n 220 \"\"\"\n 221 Place a legend on the Axes.\n 222 \n (...) 334 .. plot:: gallery[/text_labels_and_annotations/legend.py](http://localhost:8888/text_labels_and_annotations/legend.py)\n 335 \"\"\"\n 336 handles, labels, kwargs = mlegend._parse_legend_args([self], *args, **kwargs)\n--\u003e 337 self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)\n 338 self.legend_._remove_method = self._remove_legend\n 339 return self.legend_\n\nFile [~/.virtualenv/py3121env/lib/python3.12/site-packages/matplotlib/legend.py:601](http://localhost:8888/home/lukas/.virtualenv/py3121env/lib/python3.12/site-packages/matplotlib/legend.py#line=600), in Legend.__init__(self, parent, handles, labels, loc, numpoints, markerscale, markerfirst, reverse, scatterpoints, scatteryoffsets, prop, fontsize, labelcolor, borderpad, labelspacing, handlelength, handleheight, handletextpad, borderaxespad, columnspacing, ncols, mode, fancybox, shadow, title, title_fontsize, framealpha, edgecolor, facecolor, bbox_to_anchor, bbox_transform, frameon, handler_map, title_fontproperties, alignment, ncol, draggable)\n 597 color = getattr(handle, getter_name)()\n 598 if isinstance(color, np.ndarray):\n 599 if (\n 600 color.shape[0] == 1\n--\u003e 601 or np.isclose(color, color[0]).all()\n 602 ):\n 603 text.set_color(color[0])\n 604 else:\n\nIndexError: index 0 is out of bounds for axis 0 with size 0\n```\n\n### Expected outcome\n\nThe example plot should look like this:\n\n\u003cimg width=\"443\" height=\"428\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/ef1fd83a-51b2-4cf1-92f9-dfc6c1f1cf41\" /\u003e\n\n(I managed to create this figure by changing `labelcolor='linecolor'` to `labelcolor='C0'` in the provided example.)\n\nIn words:\n1) The legend label for the `histtype='step'` histogram (top right) should be the same as the one for the `histtype='bar'` histogram (top left).\n2) The scatter plot with empty markers (bottom right) should provide the same legend as the one with filled markers (bottom left), except that the legend handles should be obviously empty for the first and filled for the latter.\n3) There should be no error.\n\n### Additional information\n\nMight be related to #3670, #28153. \n\n### Operating system\n\nManjaro Linux\n\n### Matplotlib Version\n\n3.10.3\n\n### Matplotlib Backend\n\nmodule://matplotlib_inline.backend_inline\n\n### Python version\n\n3.12.1\n\n### Jupyter version\n\n4.4.2\n\n### Installation\n\npip","author":{"url":"https://github.com/lukashergt","@type":"Person","name":"lukashergt"},"datePublished":"2025-07-12T15:16:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/30298/matplotlib/issues/30298"}
| 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:43672155-c4da-238f-1064-02620fe9ddfd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E960:7586F:DB5218:12AE01A:6A52187E |
| html-safe-nonce | f110983a633e5c29cb9ebdc236674aa54551964f02a227260fb78c397e8c4d0c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTYwOjc1ODZGOkRCNTIxODoxMkFFMDFBOjZBNTIxODdFIiwidmlzaXRvcl9pZCI6Ijk2Mzg2NTEwNzY3NDMwNjY4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 17c31f5ae785e9525cda75b4d48ed9f5a9d01c8b36f8157970529525d0db957b |
| hovercard-subject-tag | issue:3225473653 |
| 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/30298/issue_layout |
| twitter:image | https://opengraph.githubassets.com/93089cf7677dc32c02a358299252ca653891ba60408d4f0930981041f76a335a/matplotlib/matplotlib/issues/30298 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/93089cf7677dc32c02a358299252ca653891ba60408d4f0930981041f76a335a/matplotlib/matplotlib/issues/30298 |
| og:image:alt | Bug summary The legend kwarg labelcolor='linecolor' does not play nicely with histtype='step' histograms or with fc='None' scatter plots, resulting in an invisible legend label for the histogram, a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lukashergt |
| 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