Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit13629a4

Browse files
authored
Merge pull request#10088 from anntzer/tick-visibility
Deprecate Tick.{gridOn,tick1On,label1On,...} in favor of set_visible.
2 parents2c1a064 +c61d71d commit13629a4

File tree

8 files changed

+279
-409
lines changed

8 files changed

+279
-409
lines changed
Lines 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

Lines 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+
fromcontextlibimportExitStack
18+
1719
frommatplotlib.axesimportAxes
1820
importmatplotlib.transformsastransforms
1921
importmatplotlib.axisasmaxis
@@ -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
classSkewXTick(maxis.XTick):
27-
defupdate_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-
returnself.get_loc()isNone
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-
defgridOn(self):
48-
return (self._gridOnand (self._has_default_loc()or
49-
transforms.interval_contains(self.get_view_interval(),
50-
self.get_loc())))
51-
52-
@gridOn.setter
53-
defgridOn(self,value):
54-
self._gridOn=value
55-
56-
@property
57-
deftick1On(self):
58-
returnself._tick1Onandself._need_lower()
59-
60-
@tick1On.setter
61-
deftick1On(self,value):
62-
self._tick1On=value
63-
64-
@property
65-
deflabel1On(self):
66-
returnself._label1Onandself._need_lower()
67-
68-
@label1On.setter
69-
deflabel1On(self,value):
70-
self._label1On=value
71-
72-
@property
73-
deftick2On(self):
74-
returnself._tick2Onandself._need_upper()
75-
76-
@tick2On.setter
77-
deftick2On(self,value):
78-
self._tick2On=value
79-
80-
@property
81-
deflabel2On(self):
82-
returnself._label2Onandself._need_upper()
83-
84-
@label2On.setter
85-
deflabel2On(self,value):
86-
self._label2On=value
29+
defdraw(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+
withExitStack()asstack:
35+
forartistin [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()andneeds_lower)
44+
self.label1.set_visible(
45+
self.label1.get_visible()andneeds_lower)
46+
self.tick2line.set_visible(
47+
self.tick2line.get_visible()andneeds_upper)
48+
self.label2.set_visible(
49+
self.label2.get_visible()andneeds_upper)
50+
super(SkewXTick,self).draw(renderer)
8751

8852
defget_view_interval(self):
8953
returnself.axes.xaxis.get_view_interval()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp