Skip to content

Commit 6a250a9

Browse files
committed
axisartist: fix set_xlim & set_ylim behavior
1 parent 408c529 commit 6a250a9

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ def get_tick_transform(self, axes):
217217
return trans_tick
218218

219219

220-
221220
class Floating(_Base):
222221
def __init__(self, nth_coord,
223222
value):
@@ -811,38 +810,6 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
811810
return _bbox
812811

813812

814-
def set_xlim(self, left=None, right=None, emit=True, auto=False,
815-
swap_axis=True, **kw):
816-
817-
x1o, x2o = self.get_xlim()
818-
819-
maxes.Axes.set_xlim(self, left, right, emit, auto, **kw)
820-
x1, x2 = self.get_xlim()
821-
822-
if not swap_axis:
823-
return
824-
825-
if (x1o > x2o and x1 < x2) or (x1o < x2o and x1 > x2):
826-
self.axis["right"], self.axis["left"] = self.axis["left"], self.axis["right"]
827-
828-
self.axis["left"].set_axis_direction("left")
829-
self.axis["right"].set_axis_direction("right")
830-
831-
832-
def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
833-
swap_axis=True, **kw):
834-
835-
y1o, y2o = self.get_ylim()
836-
837-
maxes.Axes.set_ylim(self, bottom, top, emit, auto, **kw)
838-
y1, y2 = self.get_ylim()
839-
840-
if y1o > y2o and y1 < y2 or (y1o < y2o and y1 > y2):
841-
self.axis["top"], self.axis["bottom"] = self.axis["bottom"], self.axis["top"]
842-
843-
self.axis["top"].set_axis_direction("top")
844-
self.axis["bottom"].set_axis_direction("bottom")
845-
846813

847814

848815
Subplot = maxes.subplot_class_factory(Axes)

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@ def __init__(self, grid_helper, side, nth_coord_ticks=None):
3434
self.nth_coord_ticks = nth_coord_ticks
3535

3636
self.side = side
37+
self._limits_inverted = False
3738

3839
def update_lim(self, axes):
3940
self.grid_helper.update_lim(axes)
4041

42+
if self.nth_coord == 0:
43+
xy1, xy2 = axes.get_ylim()
44+
else:
45+
xy1, xy2 = axes.get_xlim()
46+
47+
if xy1 > xy2:
48+
self._limits_inverted = True
49+
else:
50+
self._limits_inverted = False
51+
52+
4153
def change_tick_coord(self, coord_number=None):
4254
if coord_number is None:
4355
self.nth_coord_ticks = 1 - self.nth_coord_ticks
@@ -55,14 +67,21 @@ def get_tick_iterators(self, axes):
5567

5668
g = self.grid_helper
5769

58-
ti1 = g.get_tick_iterator(self.nth_coord_ticks, self.side)
59-
ti2 = g.get_tick_iterator(1-self.nth_coord_ticks, self.side, minor=True)
70+
if self._limits_inverted:
71+
side = {"left":"right","right":"left",
72+
"top":"bottom", "bottom":"top"}[self.side]
73+
else:
74+
side = self.side
75+
76+
ti1 = g.get_tick_iterator(self.nth_coord_ticks, side)
77+
ti2 = g.get_tick_iterator(1-self.nth_coord_ticks, side, minor=True)
6078

6179
#ti2 = g.get_tick_iterator(1-self.nth_coord_ticks, self.side, minor=True)
6280

6381
return chain(ti1, ti2), iter([])
6482

6583

84+
6685
class FloatingAxisArtistHelper(AxisArtistHelper.Floating):
6786

6887
def __init__(self, grid_helper, nth_coord, value, axis_direction=None):

0 commit comments

Comments
 (0)