Title: twinx plot with datetime in xaxis fails in 3.1.3 · Issue #16405 · matplotlib/matplotlib · GitHub
Open Graph Title: twinx plot with datetime in xaxis fails in 3.1.3 · Issue #16405 · matplotlib/matplotlib
X Title: twinx plot with datetime in xaxis fails in 3.1.3 · Issue #16405 · matplotlib/matplotlib
Description: Bug report Bug summary in 3.1.3 ax.twinx() with fails to plot the second plot if using datetime values for x axis. Code for reproduction import pandas as pd import matplotlib.pyplot as plt import matplotlib.dates as mdates import numpy a...
Open Graph Description: Bug report Bug summary in 3.1.3 ax.twinx() with fails to plot the second plot if using datetime values for x axis. Code for reproduction import pandas as pd import matplotlib.pyplot as plt import m...
X Description: Bug report Bug summary in 3.1.3 ax.twinx() with fails to plot the second plot if using datetime values for x axis. Code for reproduction import pandas as pd import matplotlib.pyplot as plt import m...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/16405
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"twinx plot with datetime in xaxis fails in 3.1.3","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nin 3.1.3 ax.twinx() with fails to plot the second plot if using datetime values for x axis.\r\n\r\n**Code for reproduction**\r\n\r\n\r\n\r\n```python\r\n\r\nimport pandas as pd\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.dates as mdates\r\nimport numpy as np\r\n\r\ndf = pd.DataFrame(index=pd.date_range(start='2020-01-26 22:00:00+00:00', end='2020-02-03 14:00:00+00:00', freq='H'),\r\n data=np.random.rand(185, 5), columns = ['code_200','code_201','code_500','mean_200','mean_201'] )\r\nfig, ax = plt.subplots( figsize=(15,6))\r\n# plt.figure()\r\ndfd = df.resample('D')[['code_200','code_201','code_500']].sum().tail(10)\r\n# plt.bar(dfd)\r\nplt.bar(dfd.index, dfd.code_200, color='#008c6e', label='sum of 200s')\r\nplt.bar(dfd.index, dfd.code_201, bottom=dfd.code_200, color='k', label='sum of 201s')\r\nplt.bar(dfd.index, dfd.code_500, bottom=dfd.code_200+dfd.code_201, color='#872d32',label='sum of 500s')\r\n\r\nax.yaxis.grid('both',color='k', linestyle='-', alpha=0.2)\r\nax.set_ylabel('# responses')\r\ndfm = df.resample('D')[['mean_200', 'mean_201']].mean().tail(10)\r\nax2 = ax.twinx() \r\nax2.plot(dfm.index, dfm.mean_200.values, label='avg for 200s', color='#808080')\r\nax2.plot(dfm.index, dfm.mean_201.values, label='avg for 201s', color='#872d32')\r\nax.legend(loc='upper left')\r\nax2.legend(loc='lower right')\r\nax2.set_ylabel('average response times [ms]')\r\nax.xaxis.set_major_formatter( mdates.DateFormatter('%a, %d-%b'))\r\nplt.show()\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n```\r\nax2.plot(dfm.index, dfm.mean_200.values, label='avg for 200s', color='#808080')\r\n File \"/usr/local/lib/python3.7/site-packages/matplotlib/axes/_axes.py\", line 1667, in plot\r\n self.add_line(line)\r\n File \"/usr/local/lib/python3.7/site-packages/matplotlib/axes/_base.py\", line 1902, in add_line\r\n self._update_line_limits(line)\r\n File \"/usr/local/lib/python3.7/site-packages/matplotlib/axes/_base.py\", line 1924, in _update_line_limits\r\n path = line.get_path()\r\n File \"/usr/local/lib/python3.7/site-packages/matplotlib/lines.py\", line 1027, in get_path\r\n self.recache()\r\n File \"/usr/local/lib/python3.7/site-packages/matplotlib/lines.py\", line 670, in recache\r\n x = _to_unmasked_float_array(xconv).ravel()\r\n File \"/usr/local/lib/python3.7/site-packages/matplotlib/cbook/__init__.py\", line 1390, in _to_unmasked_float_array\r\n return np.asarray(x, float)\r\n File \"/usr/local/lib/python3.7/site-packages/numpy/core/_asarray.py\", line 85, in asarray\r\n return array(a, dtype, copy=False, order=order)\r\nTypeError: float() argument must be a string or a number, not 'Timestamp'\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\r\n\r\nThe image was generated with matplotlib version 3.1.0 it fails in 3.1.3\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: Works with 3.1.0 on Windows 10 and Linux (python docker)\r\n * Matplotlib version: 3.1.0 / 3.1.3\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): agg\r\n * Python version: 3.7\r\n * Jupyter version (if applicable): nope\r\n * Other libraries: pandas = 1.0.0 and 0.24.1 both work / fail\r\n\r\nAll installed from pip.\r\n\r\n","author":{"url":"https://github.com/icfly2","@type":"Person","name":"icfly2"},"datePublished":"2020-02-04T09:51:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/16405/matplotlib/issues/16405"}
| 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:2820cdfa-57b3-ea87-fc6d-1389f601cd3b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FE4:39DD30:ACC69B:EE0516:6A57E6F1 |
| html-safe-nonce | a9cca26afe3034dba293a154600eb26dd225692a9736b4cfc509652733bfd2b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkU0OjM5REQzMDpBQ0M2OUI6RUUwNTE2OjZBNTdFNkYxIiwidmlzaXRvcl9pZCI6IjUyNDQxMTYwMzMyNDIzOTIzMDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 66131805c09f375db10dfea6b9ab60de3ddc67c74f42abd803751be14a51d4e6 |
| hovercard-subject-tag | issue:559603515 |
| 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/16405/issue_layout |
| twitter:image | https://opengraph.githubassets.com/08b2a902a30cbcdec512399720963828e5fe28d169bbb8fe6d2c6706bfd5d472/matplotlib/matplotlib/issues/16405 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/08b2a902a30cbcdec512399720963828e5fe28d169bbb8fe6d2c6706bfd5d472/matplotlib/matplotlib/issues/16405 |
| og:image:alt | Bug report Bug summary in 3.1.3 ax.twinx() with fails to plot the second plot if using datetime values for x axis. Code for reproduction import pandas as pd import matplotlib.pyplot as plt import m... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | icfly2 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 49c8c15fabcbf356d607a90ca115c13b273e42ff8b74155de050fd229a9b0121 |
| 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 | 72a32c9d47294b6b7eb7f0250253277920c7a987 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width