5
5
unicode_literals )
6
6
7
7
import itertools
8
- import six
9
8
10
- from nose .tools import assert_true
11
- import numpy as np
12
9
import matplotlib .pyplot as plt
13
- from matplotlib .testing .decorators import cleanup , image_comparison
10
+ from matplotlib .testing .decorators import image_comparison
14
11
15
12
from matplotlib .axes import Axes
16
13
import matplotlib .transforms as transforms
17
14
import matplotlib .axis as maxis
18
15
import matplotlib .spines as mspines
19
- import matplotlib .path as mpath
20
16
import matplotlib .patches as mpatch
21
17
from matplotlib .projections import register_projection
22
18
@@ -54,46 +50,31 @@ def draw(self, renderer):
54
50
# This class exists to provide two separate sets of intervals to the tick,
55
51
# as well as create instances of the custom tick
56
52
class SkewXAxis (maxis .XAxis ):
57
- def __init__ (self , * args , ** kwargs ):
58
- maxis .XAxis .__init__ (self , * args , ** kwargs )
59
- self .upper_interval = 0.0 , 1.0
60
-
61
53
def _get_tick (self , major ):
62
54
return SkewXTick (self .axes , 0 , '' , major = major )
63
55
64
56
@property
65
57
def lower_interval (self ):
66
58
return self .axes .viewLim .intervalx
67
59
60
+ @property
61
+ def upper_interval (self ):
62
+ return self .axes .upper_xlim
63
+
68
64
def get_view_interval (self ):
69
- return self .upper_interval [0 ], self .axes . viewLim . intervalx [1 ]
65
+ return self .upper_interval [0 ], self .lower_interval [1 ]
70
66
71
67
72
68
# This class exists to calculate the separate data range of the
73
69
# upper X-axis and draw the spine there. It also provides this range
74
70
# to the X-axis artist for ticking and gridlines
75
71
class SkewSpine (mspines .Spine ):
76
- def __init__ (self , axes , spine_type ):
77
- if spine_type == 'bottom' :
78
- loc = 0.0
79
- else :
80
- loc = 1.0
81
- mspines .Spine .__init__ (self , axes , spine_type ,
82
- mpath .Path ([(13 , loc ), (13 , loc )]))
83
-
84
72
def _adjust_location (self ):
85
- trans = self .axes . transDataToAxes . inverted ()
73
+ pts = self ._path . vertices
86
74
if self .spine_type == 'top' :
87
- yloc = 1.0
75
+ pts [:, 0 ] = self . axis . upper_interval
88
76
else :
89
- yloc = 0.0
90
- left = trans .transform_point ((0.0 , yloc ))[0 ]
91
- right = trans .transform_point ((1.0 , yloc ))[0 ]
92
-
93
- pts = self ._path .vertices
94
- pts [0 , 0 ] = left
95
- pts [1 , 0 ] = right
96
- self .axis .upper_interval = (left , right )
77
+ pts [:, 0 ] = self .axis .lower_interval
97
78
98
79
99
80
# This class handles registration of the skew-xaxes as a projection as well
@@ -106,7 +87,7 @@ class SkewXAxes(Axes):
106
87
name = 'skewx'
107
88
108
89
def _init_axis (self ):
109
- #Taken from Axes and modified to use our modified X-axis
90
+ # Taken from Axes and modified to use our modified X-axis
110
91
self .xaxis = SkewXAxis (self )
111
92
self .spines ['top' ].register_axis (self .xaxis )
112
93
self .spines ['bottom' ].register_axis (self .xaxis )
@@ -115,7 +96,7 @@ def _init_axis(self):
115
96
self .spines ['right' ].register_axis (self .yaxis )
116
97
117
98
def _gen_axes_spines (self ):
118
- spines = {'top' : SkewSpine (self , 'top' ),
99
+ spines = {'top' : SkewSpine . linear_spine (self , 'top' ),
119
100
'bottom' : mspines .Spine .linear_spine (self , 'bottom' ),
120
101
'left' : mspines .Spine .linear_spine (self , 'left' ),
121
102
'right' : mspines .Spine .linear_spine (self , 'right' )}
@@ -128,7 +109,7 @@ def _set_lim_and_transforms(self):
128
109
"""
129
110
rot = 30
130
111
131
- #Get the standard transform setup from the Axes base class
112
+ # Get the standard transform setup from the Axes base class
132
113
Axes ._set_lim_and_transforms (self )
133
114
134
115
# Need to put the skew in the middle, after the scale and limits,
@@ -150,6 +131,12 @@ def _set_lim_and_transforms(self):
150
131
transforms .IdentityTransform ()) +
151
132
transforms .Affine2D ().skew_deg (rot , 0 )) + self .transAxes
152
133
134
+ @property
135
+ def upper_xlim (self ):
136
+ pts = [[0. , 1. ], [1. , 1. ]]
137
+ return self .transDataToAxes .inverted ().transform (pts )[:, 0 ]
138
+
139
+
153
140
# Now register the projection with matplotlib so the user can select
154
141
# it.
155
142
register_projection (SkewXAxes )
@@ -164,7 +151,7 @@ def test_set_line_coll_dash_image():
164
151
ax .grid (True )
165
152
166
153
# An example of a slanted line at constant X
167
- l = ax .axvline (0 , color = 'b' )
154
+ ax .axvline (0 , color = 'b' )
168
155
169
156
170
157
@image_comparison (baseline_images = ['skew_rects' ], remove_text = True )
0 commit comments