Skip to content

BUG: xticklables is not correctly set when using df.plot.box with group-by  #50427

Open
@helium777

Description

@helium777

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

df = pd.DataFrame({'value': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                   'label': ['c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'a', 'a']})
df.label = pd.Categorical(df.label, categories=['c', 'b', 'a'], ordered=True)
df.plot.box(by='label')

Issue Description

If I try to plot a dataframe and group it by a categorical column, the dataframe is not correctly plotted.

image

Expected Behavior

Expected outcome should be like:

image

This image was produced by the code below.

import pandas as pd

df = pd.DataFrame({'value': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                   'label': ['c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'a', 'a']})
df.plot.box(by='label')

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.9.15.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.79.1-microsoft-standard-WSL2
Version : #1 SMP Wed Nov 23 01:01:46 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.2
numpy : 1.24.0
pytz : 2022.7
dateutil : 2.8.2
setuptools : 65.6.3
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions