Skip to content

Commit c60605e

Browse files
committed
Deprecate Tick.{gridOn,tick1On,label1On,...} in favor of set_visible.
Visibility attributes should just be set on the underlying artists (`tick.gridline.set_visible`, etc.) rather than maintaining yet another layer of control.
1 parent 4fc9288 commit c60605e

File tree

8 files changed

+267
-407
lines changed

8 files changed

+267
-407
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Deprecation of redundant `Tick` attributes
2+
``````````````````````````````````````````
3+
4+
The ``gridOn``, ``tick1On``, ``tick2On``, ``label1On``, and ``label2On``
5+
`~.Tick` attributes have been deprecated. Directly get and set the visibility
6+
on the underlying artists, available as the ``gridline``, ``tick1line``,
7+
``tick2line``, ``label1``, and ``label2`` attributes.
8+
9+
The ``label`` attribute, which was an alias for ``label1``, has been
10+
deprecated.
11+
12+
Subclasses that relied on setting the above visibility attributes needs to be
13+
updated; see e.g. :file:`examples/api/skewt.py`.

examples/specialty_plots/skewt.py

+21-61
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
axes that are not orthogonal. This is handled by including a skew component to
1111
the basic Axes transforms. Additional complexity comes in handling the fact
1212
that the upper and lower X-axes have different data ranges, which necessitates
13-
a bunch of custom classes for ticks,spines, and the axis to handle this.
13+
a bunch of custom classes for ticks, spines, and axis to handle this.
1414
1515
"""
1616

17+
from contextlib import ExitStack
18+
1719
from matplotlib.axes import Axes
1820
import matplotlib.transforms as transforms
1921
import matplotlib.axis as maxis
@@ -24,66 +26,24 @@
2426
# The sole purpose of this class is to look at the upper, lower, or total
2527
# interval as appropriate and see what parts of the tick to draw, if any.
2628
class SkewXTick(maxis.XTick):
27-
def update_position(self, loc):
28-
# This ensures that the new value of the location is set before
29-
# any other updates take place
30-
self._loc = loc
31-
super().update_position(loc)
32-
33-
def _has_default_loc(self):
34-
return self.get_loc() is None
35-
36-
def _need_lower(self):
37-
return (self._has_default_loc() or
38-
transforms.interval_contains(self.axes.lower_xlim,
39-
self.get_loc()))
40-
41-
def _need_upper(self):
42-
return (self._has_default_loc() or
43-
transforms.interval_contains(self.axes.upper_xlim,
44-
self.get_loc()))
45-
46-
@property
47-
def gridOn(self):
48-
return (self._gridOn and (self._has_default_loc() or
49-
transforms.interval_contains(self.get_view_interval(),
50-
self.get_loc())))
51-
52-
@gridOn.setter
53-
def gridOn(self, value):
54-
self._gridOn = value
55-
56-
@property
57-
def tick1On(self):
58-
return self._tick1On and self._need_lower()
59-
60-
@tick1On.setter
61-
def tick1On(self, value):
62-
self._tick1On = value
63-
64-
@property
65-
def label1On(self):
66-
return self._label1On and self._need_lower()
67-
68-
@label1On.setter
69-
def label1On(self, value):
70-
self._label1On = value
71-
72-
@property
73-
def tick2On(self):
74-
return self._tick2On and self._need_upper()
75-
76-
@tick2On.setter
77-
def tick2On(self, value):
78-
self._tick2On = value
79-
80-
@property
81-
def label2On(self):
82-
return self._label2On and self._need_upper()
83-
84-
@label2On.setter
85-
def label2On(self, value):
86-
self._label2On = value
29+
def draw(self, renderer):
30+
with ExitStack() as stack:
31+
for artist in [self.gridline, self.tick1line, self.tick2line,
32+
self.label1, self.label2]:
33+
stack.callback(artist.set_visible, artist.get_visible())
34+
needs_lower = transforms.interval_contains(
35+
self.axes.lower_xlim, self.get_loc())
36+
needs_upper = transforms.interval_contains(
37+
self.axes.upper_xlim, self.get_loc())
38+
self.tick1line.set_visible(
39+
self.tick1line.get_visible() and needs_lower)
40+
self.label1.set_visible(
41+
self.label1.get_visible() and needs_lower)
42+
self.tick2line.set_visible(
43+
self.tick2line.get_visible() and needs_upper)
44+
self.label2.set_visible(
45+
self.label2.get_visible() and needs_upper)
46+
super(SkewXTick, self).draw(renderer)
8747

8848
def get_view_interval(self):
8949
return self.axes.xaxis.get_view_interval()

0 commit comments

Comments
 (0)