Skip to content

Commit 2e732b1

Browse files
committed
BUG: Plotting use FixedLocator
For string x values or multiindex, the axis locator is now set to a FixedLocator for Line and Area plot. The ticklabel stay consistent when scaling and zooming. This impact the following issues: GH7612, GH15912, GH22334
1 parent 947bd76 commit 2e732b1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pandas/plotting/_core.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,13 @@ def get_label(i):
410410

411411
if self.orientation == 'vertical' or self.orientation is None:
412412
if self._need_to_set_index:
413-
xticklabels = [get_label(x) for x in ax.get_xticks()]
413+
xticks = ax.get_xticks()
414+
xticklabels = [get_label(x) for x in xticks]
414415
ax.set_xticklabels(xticklabels)
416+
from matplotlib.ticker import FixedLocator, FixedFormatter
417+
ax.xaxis.set_major_locator(FixedLocator(xticks))
418+
ax.xaxis.set_major_formatter(FixedFormatter(xticklabels))
419+
415420
self._apply_axis_properties(ax.xaxis, rot=self.rot,
416421
fontsize=self.fontsize)
417422
self._apply_axis_properties(ax.yaxis, fontsize=self.fontsize)
@@ -422,8 +427,12 @@ def get_label(i):
422427

423428
elif self.orientation == 'horizontal':
424429
if self._need_to_set_index:
425-
yticklabels = [get_label(y) for y in ax.get_yticks()]
430+
yticks = ax.get_yticks()
431+
yticklabels = [get_label(y) for y in yticks]
426432
ax.set_yticklabels(yticklabels)
433+
from matplotlib.ticker import FixedLocator, FixedFormatter
434+
ax.xaxis.set_major_locator(FixedLocator(yticks))
435+
ax.xaxis.set_major_formatter(FixedFormatter(yticklabels))
427436
self._apply_axis_properties(ax.yaxis, rot=self.rot,
428437
fontsize=self.fontsize)
429438
self._apply_axis_properties(ax.xaxis, fontsize=self.fontsize)

0 commit comments

Comments
 (0)