Skip to content

Commit 0a3c1d7

Browse files
souvik3333jreback
authored andcommitted
BUG: The setting xrot=0 in DataFrame.hist() doesn't work with by and subplots #30288 (#30491)
1 parent f973460 commit 0a3c1d7

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ Plotting
828828
- :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`)
829829
- :meth:`DataFrame.plot` now allow a ``backend`` keyword argument to allow changing between backends in one session (:issue:`28619`).
830830
- Bug in color validation incorrectly raising for non-color styles (:issue:`29122`).
831+
- Bug in :meth:`DataFrame.hist`, ``xrot=0`` does not work with ``by`` and subplots (:issue:`30288`).
831832

832833
Groupby/resample/rolling
833834
^^^^^^^^^^^^^^^^^^^^^^^^

pandas/plotting/_matplotlib/hist.py

Lines changed: 2 additions & 1 deletion
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

Lines changed: 18 additions & 0 deletions
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)