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
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
#!/usr/bin/python3importmatplotlib.pyplotaspltimportnumpyasnpimportpandasaspd# Create datadf=pd.DataFrame({'a': np.random.randn(1000),
'b': np.random.randn(1000)})
# Create figurefig=plt.figure()
plots=fig.subplots(2, 3)
# Create *externally* shared axesplots[0][0] =plt.subplot(231, sharex=plots[1][0])
# note: no plots[0][1] that's the twin only caseplots[0][2] =plt.subplot(233, sharex=plots[1][2])
# Create *internally* shared axes# note: no plots[0][0] that's the external only casetwin_ax1=plots[0][1].twinx()
twin_ax2=plots[0][2].twinx()
# Plot data to primary axesdf['a'].plot(ax=plots[0][0], title="External share only").set_xlabel("this label should never be visible")
df['a'].plot(ax=plots[1][0])
df['a'].plot(ax=plots[0][1], title="Internal share (twin) only").set_xlabel("this label should always be visible")
df['a'].plot(ax=plots[1][1])
df['a'].plot(ax=plots[0][2], title="Both").set_xlabel("this label should never be visible")
df['a'].plot(ax=plots[1][2])
# Plot data to twinned axesdf['b'].plot(ax=twin_ax1, color='green')
df['b'].plot(ax=twin_ax2, color='yellow')
# Do itplt.show()
Problem description
Multi-row and/or multi-column subplots can utilize shared axes.
An external share happens at axis creation when a sharex or sharey
parameter is specified.
An internal share, or twinning, occurs when an overlayed axis is created
by the Axes.twinx() or Axes.twiny() calls.
The two types of sharing can be distinguished after the fact in the
following manner. If two axes sharing an axis also have the same
position, they are not in an external axis share, they are twinned.
For externally shared axes Pandas automatically removes tick labels for
all but the last row and/or first column in
./pandas/plotting/_matplotlib/tools.py's function _handle_shared_axes().
_handle_shared_axes() should be interested in externally shared axes,
whether or not they are also twinned. It should, but doesn't, ignore
axes which are only twinned. Which means that twinned-only axes wrongly
also lose their tick labels.
The first image (produced by running the test code above) shows this, with the label on the axes in the middle spot of the top row (the one with the green plot) notably missing the "this label should always be visible" label:
Expected Output
With the proposed fix in PR #33767 the correct bevahiour is seen:
Output of pd.show_versions()
INSTALLED VERSIONS
commit : caa5121
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-40-lowlatency
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
Multi-row and/or multi-column subplots can utilize shared axes.
An external share happens at axis creation when a sharex or sharey
parameter is specified.
An internal share, or twinning, occurs when an overlayed axis is created
by the Axes.twinx() or Axes.twiny() calls.
The two types of sharing can be distinguished after the fact in the
following manner. If two axes sharing an axis also have the same
position, they are not in an external axis share, they are twinned.
For externally shared axes Pandas automatically removes tick labels for
all but the last row and/or first column in
./pandas/plotting/_matplotlib/tools.py's function _handle_shared_axes().
_handle_shared_axes() should be interested in externally shared axes,
whether or not they are also twinned. It should, but doesn't, ignore
axes which are only twinned. Which means that twinned-only axes wrongly
also lose their tick labels.
The first image (produced by running the test code above) shows this, with the label on the axes in the middle spot of the top row (the one with the green plot) notably missing the "this label should always be visible" label:
Expected Output
With the proposed fix in PR #33767 the correct bevahiour is seen:
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : caa5121
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-40-lowlatency
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.0.3
numpy : 1.18.3
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 41.1.0
Cython : 0.29.10
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.1.2
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 5.8.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.3.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : 1.1.2
numba : None
The text was updated successfully, but these errors were encountered: