Title: [Bug]: Inconsistent treatment of list of labels in `plot` when the input is a dataframe · Issue #27762 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Inconsistent treatment of list of labels in `plot` when the input is a dataframe · Issue #27762 · matplotlib/matplotlib
X Title: [Bug]: Inconsistent treatment of list of labels in `plot` when the input is a dataframe · Issue #27762 · matplotlib/matplotlib
Description: Bug summary plt.plot interprets a dataframe as a sequence of series to be plotted, one per column. Labels can be specified by setting label to a list of labels matching the number of columns. If the dataframe has only one column, though,...
Open Graph Description: Bug summary plt.plot interprets a dataframe as a sequence of series to be plotted, one per column. Labels can be specified by setting label to a list of labels matching the number of columns. If th...
X Description: Bug summary plt.plot interprets a dataframe as a sequence of series to be plotted, one per column. Labels can be specified by setting label to a list of labels matching the number of columns. If th...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27762
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Inconsistent treatment of list of labels in `plot` when the input is a dataframe","articleBody":"### Bug summary\n\n`plt.plot` interprets a dataframe as a sequence of series to be plotted, one per column. Labels can be specified by setting `label` to a list of labels matching the number of columns. If the dataframe has only one column, though, the `label` argument is interpreted as a single label, instead of a list with one element.\n\n### Code for reproduction\n\n```python\nfrom matplotlib import pyplot as plt\r\nimport pandas as pd\r\nimport numpy as np\r\n\r\nx = np.arange(5)\r\ny = pd.DataFrame({'a': x, 'b': x + 1})\r\n\r\nplt.figure('double', clear=True)\r\nplt.plot(x, y, label=['A', 'B'])\r\nplt.legend() # -\u003e ok\r\n\r\nplt.figure('single', clear=True)\r\nplt.plot(x, y.drop('b', axis=1), label=['A'])\r\nplt.legend() # -\u003e legend label is \"['A']\"\r\n\r\nplt.show()\n```\n\n\n### Actual outcome\n\n\u003cimg width=\"592\" alt=\"immagine\" src=\"https://github.com/matplotlib/matplotlib/assets/9684110/aa6abbcc-dd05-459b-b4ae-acb8a0d2e998\"\u003e\r\n\n\n### Expected outcome\n\n\u003cimg width=\"573\" alt=\"immagine\" src=\"https://github.com/matplotlib/matplotlib/assets/9684110/4dd88c38-216d-446b-a8d4-de70e299f39e\"\u003e\r\n\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nmacOS 14.2.1\n\n### Matplotlib Version\n\n3.8.2\n\n### Matplotlib Backend\n\nMacOSX\n\n### Python version\n\n3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:01:35) [Clang 16.0.6 ]\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nconda","author":{"url":"https://github.com/Gattocrucco","@type":"Person","name":"Gattocrucco"},"datePublished":"2024-02-08T22:51:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/27762/matplotlib/issues/27762"}
| 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:633589fa-4edf-730e-82c6-bd80d2cae5e3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E71C:200341:75DD03:9EB9B0:6A53041F |
| html-safe-nonce | 6081e9062ee75885c78f511b0c6c7144c3453767d39e687945067bf1f76324e5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzFDOjIwMDM0MTo3NUREMDM6OUVCOUIwOjZBNTMwNDFGIiwidmlzaXRvcl9pZCI6IjMyMTA0Mjg5NjE1OTM4NTkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a4c4c3241ae62ec12e46121603e3161184d0e2e6011a4f2616bd6344c5e186cc |
| hovercard-subject-tag | issue:2126196938 |
| 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/27762/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f69de863239f3a7de9539ff244a7392ed5358bff0e036ce442bbc752801634f4/matplotlib/matplotlib/issues/27762 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f69de863239f3a7de9539ff244a7392ed5358bff0e036ce442bbc752801634f4/matplotlib/matplotlib/issues/27762 |
| og:image:alt | Bug summary plt.plot interprets a dataframe as a sequence of series to be plotted, one per column. Labels can be specified by setting label to a list of labels matching the number of columns. If th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Gattocrucco |
| 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