|
10 | 10 | axes that are not orthogonal. This is handled by including a skew component to |
11 | 11 | the basic Axes transforms. Additional complexity comes in handling the fact |
12 | 12 | 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. |
14 | 14 |
|
15 | 15 | """ |
16 | 16 |
|
| 17 | +from contextlib import ExitStack |
| 18 | + |
17 | 19 | from matplotlib.axes import Axes |
18 | 20 | import matplotlib.transforms as transforms |
19 | 21 | import matplotlib.axis as maxis |
|
24 | 26 | # The sole purpose of this class is to look at the upper, lower, or total |
25 | 27 | # interval as appropriate and see what parts of the tick to draw, if any. |
26 | 28 | 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) |
87 | 47 |
|
88 | 48 | def get_view_interval(self): |
89 | 49 | return self.axes.xaxis.get_view_interval() |
|
0 commit comments