Categories reordered to alphabetical when plotting histograms · Issue #29235 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd

import matplotlib.pyplot as plt

df = pd.DataFrame({ 'width': [0.7, 0.2, 0.15, 0.2, 1.1], 'length': [1.5, 0.5, 1.2, 0.9, 3] }, index= ['pig', 'rabbit', 'duck', 'chicken', 'horse'])

Whether or not column is passed the order is still reordered to alphabetical.

df.hist(column=['width','length']) plt.show()

Problem description

When plotting histograms from a DataFrame (see code-snippet above) the order of subplots is not maintained. Passing column does not appear to have any effect on the ordering either.

Expected Output

Plots/subplots order equals column order in DataFrame.

Output of pd.show_versions()

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 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.24.2
pytest: 5.2.1
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: 1.2.2
pyarrow: None
xarray: 0.12.1
IPython: 7.5.0
sphinx: None
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.1.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: 4.7.1
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None