8000 Inconsistent indexes for tick label plotting by nrebena · Pull Request #28733 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Inconsistent indexes for tick label plotting #28733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Nov 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG: Generate the tick position in BarPlot using convert tools from m…
…atlab.

Generate the tick position in BarPlot using convert tools from matlab.
  • Loading branch information
nrebena committed Sep 12, 2020
commit 82a3110613d233a34cf468c8c5ae297015e7c1dd
17 changes: 13 additions & 4 deletions pandas/plotting/_matplotlib/core.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,6 @@ def __init__(self, data, **kwargs):
self.bar_width = kwargs.pop("width", 0.5)
pos = kwargs.pop("position", 0.5)
kwargs.setdefault("align", "center")
self.tick_pos = np.arange(len(data))

self.bottom = kwargs.pop("bottom", 0)
self.left = kwargs.pop("left", 0)
Expand All @@ -1356,7 +1355,7 @@ def __init__(self, data, **kwargs):
self.tickoffset = self.bar_width * pos
self.lim_offset = 0

self.ax_pos = self.tick_pos - self.tickoffset
self.ax_index = self.data.index

def _args_adjust(self):
if is_list_like(self.bottom):
Expand All @@ -1383,6 +1382,16 @@ def _make_plot(self):

for i, (label, y) in enumerate(self._iter_data(fillna=0)):
ax = self._get_ax(i)

if self.orientation == 'vertical':
ax.xaxis.update_units(self.ax_index)
self.tick_pos = ax.convert_xunits(self.ax_index)
self.ax_pos = self.tick_pos - self.tickoffset
elif self.orientation == 'horizontal':
ax.yaxis.update_units(self.ax_index)
self.tick_pos = ax.convert_yunits(self.ax_index)
self.ax_pos = self.tick_pos - self.tickoffset
Copy link
Member
@charlesdong1991 charlesdong1991 May 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this self.ax_pos = self.tick_pos - self.tickoffset can be taken out from if.. else.. clause, and no need to use it twice. the main purpose of this clause is to get self.tick_pos for bar and barh separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing.


kwds = self.kwds.copy()
if self._is_series:
kwds["color"] = colors
Expand Down Expand Up @@ -1454,8 +1463,8 @@ def _post_plot_logic(self, ax: "Axes", data):
str_index = [pprint_thing(key) for key in range(data.shape[0])]
name = self._get_index_name()

s_edge = self.ax_pos[0] - 0.25 + self.lim_offset
e_edge = self.ax_pos[-1] + 0.25 + self.bar_width + self.lim_offset
s_edge = self.ax_pos.min() - 0.25 + self.lim_offset
e_edge = self.ax_pos.max() + 0.25 + self.bar_width + self.lim_offset

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

Expand Down
0