Skip to content

Commit b195dd6

Browse files
souvik3333AlexKirko
authored andcommitted
BUG: The setting xrot=0 in DataFrame.hist() doesn't work with by and subplots pandas-dev#30288 (pandas-dev#30491)
1 parent ededc62 commit b195dd6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ Plotting
829829
- :func:`set_option` now validates that the plot backend provided to ``'plotting.backend'`` implements the backend when the option is set, rather than when a plot is created (:issue:`28163`)
830830
- :meth:`DataFrame.plot` now allow a ``backend`` keyword argument to allow changing between backends in one session (:issue:`28619`).
831831
- Bug in color validation incorrectly raising for non-color styles (:issue:`29122`).
832+
- Bug in :meth:`DataFrame.hist`, ``xrot=0`` does not work with ``by`` and subplots (:issue:`30288`).
832833

833834
Groupby/resample/rolling
834835
^^^^^^^^^^^^^^^^^^^^^^^^

pandas/plotting/_matplotlib/hist.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ def _grouped_hist(
250250
def plot_group(group, ax):
251251
ax.hist(group.dropna().values, bins=bins, **kwargs)
252252

253-
xrot = xrot or rot
253+
if xrot is None:
254+
xrot = rot
254255

255256
fig, axes = _grouped_plot(
256257
plot_group,

pandas/tests/plotting/test_hist_method.py

+18
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,24 @@ def test_tight_layout(self):
253253

254254
tm.close()
255255

256+
def test_hist_subplot_xrot(self):
257+
# GH 30288
258+
df = DataFrame(
259+
{
260+
"length": [1.5, 0.5, 1.2, 0.9, 3],
261+
"animal": ["pig", "rabbit", "pig", "pig", "rabbit"],
262+
}
263+
)
264+
axes = _check_plot_works(
265+
df.hist,
266+
filterwarnings="always",
267+
column="length",
268+
by="animal",
269+
bins=5,
270+
xrot=0,
271+
)
272+
self._check_ticks_props(axes, xrot=0)
273+
256274

257275
@td.skip_if_no_mpl
258276
class TestDataFrameGroupByPlots(TestPlotBase):

0 commit comments

Comments
 (0)