|
18 | 18 | import matplotlib.transforms as transforms |
19 | 19 | import matplotlib.axis as maxis |
20 | 20 | import matplotlib.spines as mspines |
21 | | -import matplotlib.path as mpath |
22 | 21 | from matplotlib.projections import register_projection |
23 | 22 |
|
| 23 | + |
24 | 24 | # The sole purpose of this class is to look at the upper, lower, or total |
25 | 25 | # interval as appropriate and see what parts of the tick to draw, if any. |
26 | | - |
27 | | - |
28 | 26 | class SkewXTick(maxis.XTick): |
29 | 27 | def draw(self, renderer): |
30 | 28 | if not self.get_visible(): |
@@ -56,38 +54,31 @@ def draw(self, renderer): |
56 | 54 | # This class exists to provide two separate sets of intervals to the tick, |
57 | 55 | # as well as create instances of the custom tick |
58 | 56 | class SkewXAxis(maxis.XAxis): |
59 | | - def __init__(self, *args, **kwargs): |
60 | | - maxis.XAxis.__init__(self, *args, **kwargs) |
61 | | - self.upper_interval = 0.0, 1.0 |
62 | | - |
63 | 57 | def _get_tick(self, major): |
64 | 58 | return SkewXTick(self.axes, 0, '', major=major) |
65 | 59 |
|
66 | 60 | @property |
67 | 61 | def lower_interval(self): |
68 | 62 | return self.axes.viewLim.intervalx |
69 | 63 |
|
| 64 | + @property |
| 65 | + def upper_interval(self): |
| 66 | + return self.axes.upper_xlim |
| 67 | + |
70 | 68 | def get_view_interval(self): |
71 | | - return self.upper_interval[0], self.axes.viewLim.intervalx[1] |
| 69 | + return self.upper_interval[0], self.lower_interval[1] |
72 | 70 |
|
73 | 71 |
|
74 | 72 | # This class exists to calculate the separate data range of the |
75 | 73 | # upper X-axis and draw the spine there. It also provides this range |
76 | 74 | # to the X-axis artist for ticking and gridlines |
77 | 75 | class SkewSpine(mspines.Spine): |
78 | 76 | def _adjust_location(self): |
79 | | - trans = self.axes.transDataToAxes.inverted() |
| 77 | + pts = self._path.vertices |
80 | 78 | if self.spine_type == 'top': |
81 | | - yloc = 1.0 |
| 79 | + pts[:, 0] = self.axis.upper_interval |
82 | 80 | else: |
83 | | - yloc = 0.0 |
84 | | - left = trans.transform_point((0.0, yloc))[0] |
85 | | - right = trans.transform_point((1.0, yloc))[0] |
86 | | - |
87 | | - pts = self._path.vertices |
88 | | - pts[0, 0] = left |
89 | | - pts[1, 0] = right |
90 | | - self.axis.upper_interval = (left, right) |
| 81 | + pts[:, 0] = self.axis.lower_interval |
91 | 82 |
|
92 | 83 |
|
93 | 84 | # This class handles registration of the skew-xaxes as a projection as well |
@@ -143,6 +134,12 @@ def _set_lim_and_transforms(self): |
143 | 134 | transforms.IdentityTransform()) + |
144 | 135 | transforms.Affine2D().skew_deg(rot, 0)) + self.transAxes |
145 | 136 |
|
| 137 | + @property |
| 138 | + def upper_xlim(self): |
| 139 | + pts = [[0., 1.], [1., 1.]] |
| 140 | + return self.transDataToAxes.inverted().transform(pts)[:, 0] |
| 141 | + |
| 142 | + |
146 | 143 | # Now register the projection with matplotlib so the user can select |
147 | 144 | # it. |
148 | 145 | register_projection(SkewXAxes) |
@@ -242,7 +239,7 @@ def _set_lim_and_transforms(self): |
242 | 239 | plt.grid(True) |
243 | 240 |
|
244 | 241 | # Plot the data using normal plotting functions, in this case using |
245 | | - # log scaling in Y, as dicatated by the typical meteorological plot |
| 242 | + # log scaling in Y, as dictated by the typical meteorological plot |
246 | 243 | ax.semilogy(T, p) |
247 | 244 | ax.semilogy(Td, p) |
248 | 245 |
|
|
0 commit comments