Skip to content

Commit ffe6cfd

Browse files
GiuPassarelliTomAugspurger
authored andcommitted
BUG: fix custom xticks in bar() plotting function (pandas-dev#28172)
* Fixing issue pandas-dev#14119
1 parent b106108 commit ffe6cfd

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ Plotting
263263
- Bug in :meth:`DataFrame.plot` when ``kind='box'`` and data contains datetime or timedelta data. These types are now automatically dropped (:issue:`22799`)
264264
- Bug in :meth:`DataFrame.plot.line` and :meth:`DataFrame.plot.area` produce wrong xlim in x-axis (:issue:`27686`, :issue:`25160`, :issue:`24784`)
265265
- Bug where :meth:`DataFrame.boxplot` would not accept a `color` parameter like `DataFrame.plot.box` (:issue:`26214`)
266+
- Bug in the ``xticks`` argument being ignored for :meth:`DataFrame.plot.bar` (:issue:`14119`)
266267
- :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`)
267268

268269
Groupby/resample/rolling

pandas/plotting/_matplotlib/core.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,13 @@ def _post_plot_logic(self, ax, data):
14351435

14361436
def _decorate_ticks(self, ax, name, ticklabels, start_edge, end_edge):
14371437
ax.set_xlim((start_edge, end_edge))
1438-
ax.set_xticks(self.tick_pos)
1439-
ax.set_xticklabels(ticklabels)
1438+
1439+
if self.xticks is not None:
1440+
ax.set_xticks(np.array(self.xticks))
1441+
else:
1442+
ax.set_xticks(self.tick_pos)
1443+
ax.set_xticklabels(ticklabels)
1444+
14401445
if name is not None and self.use_index:
14411446
ax.set_xlabel(name)
14421447

pandas/tests/plotting/test_series.py

+7
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,13 @@ def test_xticklabels(self):
871871
exp = ["P{i:02d}".format(i=i) for i in [0, 3, 5, 9]]
872872
self._check_text_labels(ax.get_xticklabels(), exp)
873873

874+
def test_xtick_barPlot(self):
875+
# GH28172
876+
s = pd.Series(range(10), index=["P{i:02d}".format(i=i) for i in range(10)])
877+
ax = s.plot.bar(xticks=range(0, 11, 2))
878+
exp = np.array(list(range(0, 11, 2)))
879+
tm.assert_numpy_array_equal(exp, ax.get_xticks())
880+
874881
def test_custom_business_day_freq(self):
875882
# GH7222
876883
from pandas.tseries.offsets import CustomBusinessDay

0 commit comments

Comments
 (0)