Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 13629a4

Browse filesBrowse files
authored
Merge pull request #10088 from anntzer/tick-visibility
Deprecate Tick.{gridOn,tick1On,label1On,...} in favor of set_visible.
2 parents 2c1a064 + c61d71d commit 13629a4
Copy full SHA for 13629a4

File tree

Expand file treeCollapse file tree

8 files changed

+279
-409
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+279
-409
lines changed
+13Lines changed: 13 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: examples/specialty_plots/skewt.py
+25-61Lines changed: 25 additions & 61 deletions
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,28 @@
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+
# When adding the callbacks with `stack.callback`, we fetch the current
31+
# visibility state of the artist with `get_visible`; the ExitStack will
32+
# restore these states (`set_visible`) at the end of the block (after
33+
# the draw).
34+
with ExitStack() as stack:
35+
for artist in [self.gridline, self.tick1line, self.tick2line,
36+
self.label1, self.label2]:
37+
stack.callback(artist.set_visible, artist.get_visible())
38+
needs_lower = transforms.interval_contains(
39+
self.axes.lower_xlim, self.get_loc())
40+
needs_upper = transforms.interval_contains(
41+
self.axes.upper_xlim, self.get_loc())
42+
self.tick1line.set_visible(
43+
self.tick1line.get_visible() and needs_lower)
44+
self.label1.set_visible(
45+
self.label1.get_visible() and needs_lower)
46+
self.tick2line.set_visible(
47+
self.tick2line.get_visible() and needs_upper)
48+
self.label2.set_visible(
49+
self.label2.get_visible() and needs_upper)
50+
super(SkewXTick, self).draw(renderer)
8751

8852
def get_view_interval(self):
8953
return self.axes.xaxis.get_view_interval()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.