Title: Use data argument for scatter plotting timestamps from pandas · Issue #11391 · matplotlib/matplotlib · GitHub
Open Graph Title: Use data argument for scatter plotting timestamps from pandas · Issue #11391 · matplotlib/matplotlib
X Title: Use data argument for scatter plotting timestamps from pandas · Issue #11391 · matplotlib/matplotlib
Description: Bug report Bug summary This may be either a bug report or a feature request, depending how you view things. The issue is that you cannot use the data argument to scatter to plot a pandas dataframe Timestamp column. Code for reproduction ...
Open Graph Description: Bug report Bug summary This may be either a bug report or a feature request, depending how you view things. The issue is that you cannot use the data argument to scatter to plot a pandas dataframe ...
X Description: Bug report Bug summary This may be either a bug report or a feature request, depending how you view things. The issue is that you cannot use the data argument to scatter to plot a pandas dataframe ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/11391
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use data argument for scatter plotting timestamps from pandas","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\nThis may be either a bug report or a feature request, depending how you view things. The issue is that you cannot use the `data` argument to `scatter` to plot a pandas dataframe `Timestamp` column.\r\n\r\n**Code for reproduction**\r\n\r\nConsider the following data\r\n\r\n```\r\nimport matplotlib.pyplot as plt\r\nimport pandas as pd\r\nimport numpy as np; np.random.seed(42)\r\n\r\ndf = pd.DataFrame(np.random.rand(10,2), columns=[\"x\",\"y\"])\r\ndf[\"time\"] = pd.date_range(\"2018-01-01\", periods=10, freq=\"D\")\r\n```\r\n\r\n\r\nUsing the `data` argument, you may plot\r\n\r\n plt.plot(\"x\", \"y\", data=df)\r\n\r\nYou may equally plot\r\n\r\n plt.plot(\"time\", \"y\", data=df)\r\n\r\nYou may also scatter\r\n\r\n plt.scatter(x=\"x\", y=\"y\", data=df)\r\n\r\n**However, you may not scatter the timestamps**\r\n\r\n plt.scatter(x=\"time\", y=\"y\", data=df)\r\n\r\nThis fails with a `TypeError: invalid type promotion`\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"D:/.../test/GI_scatterdataarg.py\", line 40, in \u003cmodule\u003e\r\n plt.scatter(x=\"time\", y=\"y\", data=df)\r\n File \"d:\\...\\matplotlib\\lib\\matplotlib\\pyplot.py\", line 2623, in scatter\r\n verts=verts, edgecolors=edgecolors, data=data, **kwargs)\r\n File \"d:\\...\\matplotlib\\lib\\matplotlib\\__init__.py\", line 1775, in inner\r\n return func(ax, *args, **kwargs)\r\n File \"d:\\...\\matplotlib\\lib\\matplotlib\\axes\\_axes.py\", line 3982, in scatter\r\n offsets = np.column_stack([x, y])\r\n File \"D:\\...\\matplotlib\\lib\\site-packages\\numpy\\lib\\shape_base.py\", line 369, in column_stack\r\n return _nx.concatenate(arrays, 1)\r\nTypeError: invalid type promotion\r\n```\r\n\r\nThis is a bit surprising since you may well plot timestamps through scatter\r\n\r\n plt.scatter(x=df.time.values, y=df.x.values)\r\n\r\njust not through the `data` argument. \r\n\r\n**Expected outcome**\r\n\r\nGiven that one may plot the timestamps correctly with `plot` and timestamps with `scatter` by providing the values, it would be nice to be able to use the `data` argument with `scatter` as well.\r\n\r\n... and ideally with `bar`, `fill_between` etc. ;-)\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: Win 8.1\r\n * Matplotlib version: master 2.2.2.post1270+g6665bc739\r\n * Matplotlib backend: Qt5Agg\r\n * Python version: 3.6\r\n * Jupyter version (if applicable):\r\n * Other libraries: Pandas 0.22.0\r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n","author":{"url":"https://github.com/ImportanceOfBeingErnest","@type":"Person","name":"ImportanceOfBeingErnest"},"datePublished":"2018-06-06T22:53:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/11391/matplotlib/issues/11391"}
| 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:086818ed-601d-5e8a-c032-f7f983638682 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFDC:2790A:2936A8E:3BA3271:6A551438 |
| html-safe-nonce | b9fea5f7124e0c73f15323191357e55a1742cae144e0aaba078332485709d902 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkRDOjI3OTBBOjI5MzZBOEU6M0JBMzI3MTo2QTU1MTQzOCIsInZpc2l0b3JfaWQiOiI1MjQ4MDk2NDA1OTQ0NDUzNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ee6cd531c58efb680991032517b33767868a87634b95024ed89ec4f10ba0db89 |
| hovercard-subject-tag | issue:330060206 |
| 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/11391/issue_layout |
| twitter:image | https://opengraph.githubassets.com/efbb0d69b54f6482a537752e4548a268304b4cc4c83c469fc469f1ffbdd3dcac/matplotlib/matplotlib/issues/11391 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/efbb0d69b54f6482a537752e4548a268304b4cc4c83c469fc469f1ffbdd3dcac/matplotlib/matplotlib/issues/11391 |
| og:image:alt | Bug report Bug summary This may be either a bug report or a feature request, depending how you view things. The issue is that you cannot use the data argument to scatter to plot a pandas dataframe ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ImportanceOfBeingErnest |
| hostname | github.com |
| expected-hostname | github.com |
| None | 682d273eacb2ac51680c6eb9c0b270f029f7ce74c32090f319083c34497e28a5 |
| 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 | 3b6d37c6470adadff4194742daaab9a817cc4980 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width