You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import pandas as pd
import matplotlib.pyplot as plt
x1 = pd.date_range(start='2018-03-02 12:00:00', end='2019-10-21 12:00:00', freq='1h')
df1 = pd.DataFrame([0]*len(x1), index=x1, columns=['x1'])
x2 = pd.date_range(start='2017-06-04 06:00:01', end='2019-11-10 06:00:01', freq='1h')
df2 = pd.DataFrame([0]*len(x2), index=x2, columns=['x2'])
fig, axes = plt.subplots(nrows=4, ncols=1, sharex=True)
df1.plot(ax=axes[0])
df2.plot(ax=axes[1])
axes[2].plot(df1)
axes[3].plot(df2)
#Autoscale doesn't affect this issue. Just used to make all lines visible from start.
plt.autoscale(enable=True, axis='both', tight=None)
for ax in axes:
ax.legend().remove()
# printouts
print(str(axes[0].get_xlim()))
print(str(axes[1].get_xlim()))
print(str(axes[2].get_xlim()))
print(str(axes[3].get_xlim()))
plt.show()
Problem description
The x-axes are misaligned when plotting two or more subplots and have different timestep base (in the example above, x1 starts with hour:minute:second 00:00:00 while x2 starts with 06:00:01.
UPDATE: Also, plotting df1 using axes[2].plot(df1) instead of df1.plot(ax=axes[0]) works perfectly.
If plt.autoscale is not used, the topmost plot, df1.plot(ax=axes[0]), is not visible unless one pan the axes manually.
The result from get_xlim() from the supplied code returns
Code Sample, a copy-pastable example if possible
Problem description
The x-axes are misaligned when plotting two or more subplots and have different timestep base (in the example above, x1 starts with hour:minute:second 00:00:00 while x2 starts with 06:00:01.
UPDATE: Also, plotting df1 using axes[2].plot(df1) instead of df1.plot(ax=axes[0]) works perfectly.
If plt.autoscale is not used, the topmost plot, df1.plot(ax=axes[0]), is not visible unless one pan the axes manually.
The result from get_xlim() from the supplied code returns
If the df2.plot(ax=axes[1]) is plotted before the other three, the result of the get_xlim() is instead
This issue might be related to:
#11574, #18571 and #29705.
Expected Output
Plotting the data at the correct x axis coordinates.
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit : None
python : 3.6.8.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-65-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : sv_SE.UTF-8
LOCALE : sv_SE.UTF-8
pandas : 0.25.3
numpy : 1.17.4
pytz : 2019.3
dateutil : 2.8.1
pip : 9.0.1
setuptools : 40.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.2.1
html5lib : 0.999999999
pymysql : None
psycopg2 : 2.7.4 (dt dec pq3 ext lo64)
jinja2 : 2.10
IPython : None
pandas_datareader: None
bs4 : 4.6.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.2.1
matplotlib : 3.0.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.2.0
sqlalchemy : None
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: