Repository navigation
Closed
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 as np
df = 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'),
data=np.random.rand(185, 5), columns = ['code_200','code_201','code_500','mean_200','mean_201'] )
fig, ax = plt.subplots( figsize=(15,6))
# plt.figure()
dfd = df.resample('D')[['code_200','code_201','code_500']].sum().tail(10)
# plt.bar(dfd)
plt.bar(dfd.index, dfd.code_200, color='#008c6e', label='sum of 200s')
plt.bar(dfd.index, dfd.code_201, bottom=dfd.code_200, color='k', label='sum of 201s')
plt.bar(dfd.index, dfd.code_500, bottom=dfd.code_200+dfd.code_201, color='#872d32',label='sum of 500s')
ax.yaxis.grid('both',color='k', linestyle='-', alpha=0.2)
ax.set_ylabel('# responses')
dfm = df.resample('D')[['mean_200', 'mean_201']].mean().tail(10)
ax2 = ax.twinx()
ax2.plot(dfm.index, dfm.mean_200.values, label='avg for 200s', color='#808080')
ax2.plot(dfm.index, dfm.mean_201.values, label='avg for 201s', color='#872d32')
ax.legend(loc='upper left')
ax2.legend(loc='lower right')
ax2.set_ylabel('average response times [ms]')
ax.xaxis.set_major_formatter( mdates.DateFormatter('%a, %d-%b'))
plt.show()Actual outcome
ax2.plot(dfm.index, dfm.mean_200.values, label='avg for 200s', color='#808080')
File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 1667, in plot
self.add_line(line)
File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 1902, in add_line
self._update_line_limits(line)
File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 1924, in _update_line_limits
path = line.get_path()
File "/usr/local/lib/python3.7/site-packages/matplotlib/lines.py", line 1027, in get_path
self.recache()
File "/usr/local/lib/python3.7/site-packages/matplotlib/lines.py", line 670, in recache
x = _to_unmasked_float_array(xconv).ravel()
File "/usr/local/lib/python3.7/site-packages/matplotlib/cbook/__init__.py", line 1390, in _to_unmasked_float_array
return np.asarray(x, float)
File "/usr/local/lib/python3.7/site-packages/numpy/core/_asarray.py", line 85, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'Timestamp'
Expected outcome
The image was generated with matplotlib version 3.1.0 it fails in 3.1.3
Matplotlib version
- Operating system: Works with 3.1.0 on Windows 10 and Linux (python docker)
- Matplotlib version: 3.1.0 / 3.1.3
- Matplotlib backend (
print(matplotlib.get_backend())): agg - Python version: 3.7
- Jupyter version (if applicable): nope
- Other libraries: pandas = 1.0.0 and 0.24.1 both work / fail
All installed from pip.

Activity
anntzer commentedon Feb 4, 2020
On 3.1.x this bisects to #16382, but this is not present in master even though the same commit is there.
timhoffm commentedon Feb 4, 2020
Works for me both on 3.1.x and master (tested with pandas 0.24.1 and numpy 1.16.2). Maybe the numpy version is relevant as well?
jklymak commentedon Feb 5, 2020
works
numpy = 1.17.5,panda = 1.0.0icfly2 commentedon Feb 5, 2020
I'll recreate the docker container with the failing plot later and report back the full requirements / dependencies. The change in matplotlib version was what fixed it though.
icfly2 commentedon Feb 5, 2020
The code:
Works with:
Both on a python:37 docker container running on RHEL server, through django shell
icfly2 commentedon Feb 5, 2020
Django>=2.0,<3.0
psycopg2>=2.7,<3.0
matplotlib==3.1.0 # this works 3.1.3 and it fails # 3.1.2 and it works
pandas==1.0
numpy==1.18.1
jklymak commentedon Feb 5, 2020
numpy=1.18.1, pandas=1.0, v3.1.x on master and this works fine. I would guess you have an install crossed somewhere.
jklymak commentedon Feb 11, 2020
I'm going to close this because we can't reproduce, but feel free to follow up if its still a problem.
adfernandes commentedon Mar 25, 2020
Same error on macOS, using Conda with
numpy == 1.18.1,matplotlib == 3.1.3, andpandas == 1.0.2.I have a
DateTimeIndexx-axis, and get the errorAnd it is a clean environment, exported and re-imported, with no version conflicts (and all packages up-to-date).
The sample code at the top of this PR fails for me, also, with the same error.