Skip to content

Commit 4e39aba

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 2377a6a commit 4e39aba

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
@@ -1308,7 +1308,6 @@ def __init__(self, data, **kwargs):
13081308
self.bar_width = kwargs.pop("width", 0.5)
13091309
pos = kwargs.pop("position", 0.5)
13101310
kwargs.setdefault("align", "center")
1311-
self.tick_pos = np.arange(len(data))
13121311

13131312
self.bottom = kwargs.pop("bottom", 0)
13141313
self.left = kwargs.pop("left", 0)
@@ -1331,7 +1330,7 @@ def __init__(self, data, **kwargs):
13311330
self.tickoffset = self.bar_width * pos
13321331
self.lim_offset = 0
13331332

1334-
self.ax_pos = self.tick_pos - self.tickoffset
1333+
self.ax_index = self.data.index
13351334

13361335
def _args_adjust(self):
13371336
if is_list_like(self.bottom):
@@ -1358,6 +1357,16 @@ def _make_plot(self):
13581357

13591358
for i, (label, y) in enumerate(self._iter_data(fillna=0)):
13601359
ax = self._get_ax(i)
1360+
1361+
if self.orientation == 'vertical':
1362+
ax.xaxis.update_units(self.ax_index)
1363+
self.tick_pos = ax.convert_xunits(self.ax_index)
1364+
self.ax_pos = self.tick_pos - self.tickoffset
1365+
elif self.orientation == 'horizontal':
1366+
ax.yaxis.update_units(self.ax_index)
1367+
self.tick_pos = ax.convert_yunits(self.ax_index)
1368+
self.ax_pos = self.tick_pos - self.tickoffset
1369+
13611370
kwds = self.kwds.copy()
13621371
if self._is_series:
13631372
kwds["color"] = colors
@@ -1429,8 +1438,8 @@ def _post_plot_logic(self, ax, data):
14291438
str_index = [pprint_thing(key) for key in range(data.shape[0])]
14301439
name = self._get_index_name()
14311440

1432-
s_edge = self.ax_pos[0] - 0.25 + self.lim_offset
1433-
e_edge = self.ax_pos[-1] + 0.25 + self.bar_width + self.lim_offset
1441+
s_edge = self.ax_pos.min() - 0.25 + self.lim_offset
1442+
e_edge = self.ax_pos.max() + 0.25 + self.bar_width + self.lim_offset
14341443

14351444
self._decorate_ticks(ax, name, str_index, s_edge, e_edge)
14361445

0 commit comments

Comments
 (0)