Skip to content

Commit 966e77b

Browse files
committed
BUG: Generate the tick position in BarPlot using convert tools from matlab.
Generate the tick position in BarPlot using convert tools from matlab.
1 parent 05eed69 commit 966e77b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,6 @@ def __init__(self, data, **kwargs):
12951295
self.bar_width = kwargs.pop("width", 0.5)
12961296
pos = kwargs.pop("position", 0.5)
12971297
kwargs.setdefault("align", "center")
1298-
self.tick_pos = np.arange(len(data))
12991298

13001299
self.bottom = kwargs.pop("bottom", 0)
13011300
self.left = kwargs.pop("left", 0)
@@ -1318,7 +1317,7 @@ def __init__(self, data, **kwargs):
13181317
self.tickoffset = self.bar_width * pos
13191318
self.lim_offset = 0
13201319

1321-
self.ax_pos = self.tick_pos - self.tickoffset
1320+
self.ax_index = self.data.index
13221321

13231322
def _args_adjust(self):
13241323
if is_list_like(self.bottom):
@@ -1345,6 +1344,16 @@ def _make_plot(self):
13451344

13461345
for i, (label, y) in enumerate(self._iter_data(fillna=0)):
13471346
ax = self._get_ax(i)
1347+
1348+
if self.orientation == 'vertical':
1349+
ax.xaxis.update_units(self.ax_index)
1350+
self.tick_pos = ax.convert_xunits(self.ax_index)
1351+
self.ax_pos = self.tick_pos - self.tickoffset
1352+
elif self.orientation == 'horizontal':
1353+
ax.yaxis.update_units(self.ax_index)
1354+
self.tick_pos = ax.convert_yunits(self.ax_index)
1355+
self.ax_pos = self.tick_pos - self.tickoffset
1356+
13481357
kwds = self.kwds.copy()
13491358
if self._is_series:
13501359
kwds["color"] = colors
@@ -1416,8 +1425,8 @@ def _post_plot_logic(self, ax, data):
14161425
str_index = [pprint_thing(key) for key in range(data.shape[0])]
14171426
name = self._get_index_name()
14181427

1419-
s_edge = self.ax_pos[0] - 0.25 + self.lim_offset
1420-
e_edge = self.ax_pos[-1] + 0.25 + self.bar_width + self.lim_offset
1428+
s_edge = self.ax_pos.min() - 0.25 + self.lim_offset
1429+
e_edge = self.ax_pos.max() + 0.25 + self.bar_width + self.lim_offset
14211430

14221431
self._decorate_ticks(ax, name, str_index, s_edge, e_edge)
14231432

0 commit comments

Comments
 (0)