BUG: df.plot.box does not handle well when matplotlib Axes uses sharey=True · Issue #54941 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

This is a similar issue to #36918 that has been fixed for df.boxplot. But the issue remains for df.plot.box:

import matplotlib.pyplot as plt import numpy as np import pandas as pd

rng = np.random.default_rng(0) df1 = pd.DataFrame( rng.integers(0, 100, size=(100, 4)), columns=list('ABCD') ) df2 = pd.DataFrame( rng.integers(0, 100, size=(100, 4)), columns=list('ABCD') )

f, axs = plt.subplots(1, 2, figsize=(10, 7), sharey=True) df1.plot.box(ax=axs[0], showfliers=False, vert=False) df2.plot.box(ax=axs[1], showfliers=False, vert=False)

Issue Description

The current code raise an error:

ValueError: The number of FixedLocator locations (8), usually from a call to set_ticks, does not match the number of ticklabels (4).

Expected Behavior

No errors

Installed Versions

INSTALLED VERSIONS

commit : 9994adcfa12064ec0eb535786c43a93ec6aff15f python : 3.10.12.final.0 python-bits : 64 OS : Darwin OS-release : 22.6.0 Version : Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : None.UTF-8

pandas : 2.2.0dev0+164.g9994adcfa1 numpy : 1.24.4 pytz : 2023.3 dateutil : 2.8.2 setuptools : 68.1.2 pip : 23.2.1 Cython : 0.29.33 pytest : 7.4.0 hypothesis : 6.83.0 sphinx : 6.2.1 blosc : None feather : None xlsxwriter : 3.1.2 lxml.etree : 4.9.3 html5lib : 1.1 pymysql : 1.4.6 psycopg2 : 2.9.6 jinja2 : 3.1.2 IPython : 8.15.0 pandas_datareader : None bs4 : 4.12.2 bottleneck : 1.3.7 dataframe-api-compat: None fastparquet : 2023.7.0 fsspec : 2023.6.0 gcsfs : 2023.6.0 matplotlib : 3.7.2 numba : 0.57.1 numexpr : 2.8.4 odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 13.0.0 pyreadstat : 1.2.3 pyxlsb : 1.0.10 s3fs : 2023.6.0 scipy : 1.11.2 sqlalchemy : 2.0.20 tables : 3.8.0 tabulate : 0.9.0 xarray : 2023.8.0 xlrd : 2.0.1 zstandard : 0.19.0 tzdata : 2023.3 qtpy : None pyqt5 : None