-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
Code Sample
import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib as mpl df=pd.DataFrame() t1 = np.arange(1, 9.0, 1) df['TIME'] = t1 df['DAT1'] = t1 df['DAT2'] = np.arange(9, 1.0, -1) fig = plt.figure(constrained_layout=True) gs = mpl.gridspec.GridSpec(2, 3, figure=fig) ax1 = fig.add_subplot(gs[0, :]) ax3 = fig.add_subplot(gs[1, :]) color = 'tab:red' ax1.set_xlabel('time (s)') ax1.set_ylabel('exp', color=color) df.plot(ax=ax1, x='TIME', y='DAT1') ax1.tick_params(axis='y', labelcolor=color) **ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis color = 'tab:blue' ax2.set_ylabel('sin', color=color) # we already handled the x-label with ax1 df.plot(ax=ax1, x='TIME', y='DAT2') ax2.tick_params(axis='y', labelcolor=color)** fig.tight_layout() # otherwise the right y-label is slightly clipped plt.show()Problem description
When using GridSpec to set the layout, xlabels are not displayed if twinx is used

If the following code is commented out:
“”“
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
color = 'tab:blue'
ax2.set_ylabel('sin', color=color) # we already handled the x-label with ax1
df.plot(ax=ax1, x='TIME', y='DAT2')
ax2.tick_params(axis='y', labelcolor=color)
”“”
You can see that xlabel can be displayed:

Expected Output
show xlabels
Output of pd.show_versions()
[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS
commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 23 Stepping 10, GenuineIntel
byteorder: little
LC_ALL: None
LANG: zh_CN
LOCALE: None.None
pandas: 0.24.2
pytest: 4.3.1
pip: 19.0.3
setuptools: 40.8.0
Cython: 0.29.6
numpy: 1.16.2
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.4.0
sphinx: 1.8.5
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: 1.2.1
tables: 3.5.1
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: 2.6.1
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.5
lxml.etree: 4.3.2
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None