Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The setting xrot=0 in DataFrame.hist() doesn't work with by and subplots #30288

Closed
PavloFesenko opened this issue Dec 16, 2019 · 10 comments · Fixed by #30491
Closed

The setting xrot=0 in DataFrame.hist() doesn't work with by and subplots #30288

PavloFesenko opened this issue Dec 16, 2019 · 10 comments · Fixed by #30491
Assignees
Milestone

Comments

@PavloFesenko
Copy link

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({
    'length': [1.5, 0.5, 1.2, 0.9, 3],
    'animal': ['pig', 'rabbit', 'pig', 'pig', 'rabbit']
})
df.hist(column='length', by='animal', bins=5, xrot=0);

Problem description

The setting xrot=0 doesn't work when I use the option by in DataFrame.hist() (see the screenshot below). The temporary workaround is to set it to a very small value like xrot=0.001.

image

Expected Output

Should look like this instead
image

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1062.4.1.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.2
numpy : 1.17.2
pytz : 2019.3
dateutil : 2.8.0
pip : 19.3.1
setuptools : 41.4.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : 3.0.2
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

@jbrockmendel jbrockmendel added the Visualization plotting label Dec 18, 2019
@TomAugspurger
Copy link
Contributor

xrot = xrot or rot

should probably be

if xrot is None:
    xrot = rot

since 0 evaluates to False. A PR fixing that + adding a test would be welcome.

@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Dec 20, 2019
@souvik3333
Copy link
Contributor

Hi, Can I do it?

@souvik3333
Copy link
Contributor

I am taking this as no one seems to be working on this.

@souvik3333
Copy link
Contributor

take

@souvik3333
Copy link
Contributor

should probably be

if xrot is None:
    xrot = rot

since 0 evaluates to False. A PR fixing that + adding a test would be welcome.

Looks like

is causing the error. Assigning self.rot=0 solves the problem. I will add a PR on this. Also @TomAugspurger the solution you said fixes another issue. Should I add that in the same PR or create another issue on this?

@charlesdong1991
Copy link
Member

charlesdong1991 commented Dec 23, 2019

thanks for working on it!
@souvik3333 i think the error is not caused by self.rot=30, this is only used for plotting ts data

and i do think if you follow @TomAugspurger 's suggestion, should be able to fix the bug.

@souvik3333
Copy link
Contributor

i do think if you follow @TomAugspurger 's suggestion, should be able to fix the bug.

I tried that but it's not working. Looks like

def plot_group(group, ax):
function is not even getting called during the execution of the example given above.

@souvik3333
Copy link
Contributor

I have my doubt but I think the following is the problem.
In dataframe.plot if we have either of subplots=True or sharex=True then it's treated as irregular TS object because of this condition:

or (self.subplots and self.sharex)

So, when rot argument is not present in dataframe.plot then it is rotated 30deg. So should I update the condition @TomAugspurger @charlesdong1991 ?

@charlesdong1991
Copy link
Member

charlesdong1991 commented Dec 25, 2019

emm, okay, it seems indeed if both subplots and sharex are True, then will rot to 30. And this should be designed on purpose.

Regarding your question: I did not look at the codebase, but my assumption is when using hist and use by to plot, then subplots and sharex are automatically set to True.

Just follow your investigation, and you could either submit a PR or open a new issue if you think there is another bug. @souvik3333

@souvik3333
Copy link
Contributor

Oh, actually this bug will be fixed as @TomAugspurger said. I misplaced it with another bug I found. My apologies. I will add a new issue on that bug and add a PR on this shortly.

souvik3333 added a commit to souvik3333/pandas that referenced this issue Dec 26, 2019
@jreback jreback modified the milestones: Contributions Welcome, 1.0 Dec 27, 2019
keechongtan added a commit to keechongtan/pandas that referenced this issue Dec 29, 2019
…ndexing-1row-df

* upstream/master: (333 commits)
  CI: troubleshoot Web_and_Docs failing (pandas-dev#30534)
  WARN: Ignore NumbaPerformanceWarning in test suite (pandas-dev#30525)
  DEPR: camelCase in offsets, get_offset (pandas-dev#30340)
  PERF: implement scalar ops blockwise (pandas-dev#29853)
  DEPR: Remove Series.compress (pandas-dev#30514)
  ENH: Add numba engine for rolling apply (pandas-dev#30151)
  [ENH] Add to_markdown method (pandas-dev#30350)
  DEPR: Deprecate pandas.np module (pandas-dev#30386)
  ENH: Add ignore_index for df.drop_duplicates (pandas-dev#30405)
  BUG: The setting xrot=0 in DataFrame.hist() doesn't work with by and subplots pandas-dev#30288 (pandas-dev#30491)
  CI: Fix GBQ Tests (pandas-dev#30478)
  Bug groupby quantile listlike q and int columns (pandas-dev#30485)
  ENH: Add ignore_index for df.sort_values and series.sort_values (pandas-dev#30402)
  TYP: Typing hints in pandas/io/formats/{css,csvs}.py (pandas-dev#30398)
  BUG: raise on non-hashable Index name, closes pandas-dev#29069 (pandas-dev#30335)
  Replace "foo!r" to "repr(foo)" syntax pandas-dev#29886 (pandas-dev#30502)
  BUG: preserve EA dtype in transpose (pandas-dev#30091)
  BLD: add check to prevent tempita name error, clsoes pandas-dev#28836 (pandas-dev#30498)
  REF/TST: method-specific files for test_append (pandas-dev#30503)
  marked unused parameters (pandas-dev#30504)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants