Skip to content

Commit 42d5097

Browse files
committed
MNT: Clean up skew test
Make it match the refactoring on the example.
1 parent 7494655 commit 42d5097

File tree

1 file changed

+19
-32
lines changed

1 file changed

+19
-32
lines changed

lib/matplotlib/tests/test_skew.py

+19-32
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55
unicode_literals)
66

77
import itertools
8-
import six
98

10-
from nose.tools import assert_true
11-
import numpy as np
129
import matplotlib.pyplot as plt
13-
from matplotlib.testing.decorators import cleanup, image_comparison
10+
from matplotlib.testing.decorators import image_comparison
1411

1512
from matplotlib.axes import Axes
1613
import matplotlib.transforms as transforms
1714
import matplotlib.axis as maxis
1815
import matplotlib.spines as mspines
19-
import matplotlib.path as mpath
2016
import matplotlib.patches as mpatch
2117
from matplotlib.projections import register_projection
2218

@@ -54,46 +50,31 @@ def draw(self, renderer):
5450
# This class exists to provide two separate sets of intervals to the tick,
5551
# as well as create instances of the custom tick
5652
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-
6153
def _get_tick(self, major):
6254
return SkewXTick(self.axes, 0, '', major=major)
6355

6456
@property
6557
def lower_interval(self):
6658
return self.axes.viewLim.intervalx
6759

60+
@property
61+
def upper_interval(self):
62+
return self.axes.upper_xlim
63+
6864
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]
7066

7167

7268
# This class exists to calculate the separate data range of the
7369
# upper X-axis and draw the spine there. It also provides this range
7470
# to the X-axis artist for ticking and gridlines
7571
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-
8472
def _adjust_location(self):
85-
trans = self.axes.transDataToAxes.inverted()
73+
pts = self._path.vertices
8674
if self.spine_type == 'top':
87-
yloc = 1.0
75+
pts[:, 0] = self.axis.upper_interval
8876
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
9778

9879

9980
# This class handles registration of the skew-xaxes as a projection as well
@@ -106,7 +87,7 @@ class SkewXAxes(Axes):
10687
name = 'skewx'
10788

10889
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
11091
self.xaxis = SkewXAxis(self)
11192
self.spines['top'].register_axis(self.xaxis)
11293
self.spines['bottom'].register_axis(self.xaxis)
@@ -115,7 +96,7 @@ def _init_axis(self):
11596
self.spines['right'].register_axis(self.yaxis)
11697

11798
def _gen_axes_spines(self):
118-
spines = {'top': SkewSpine(self, 'top'),
99+
spines = {'top': SkewSpine.linear_spine(self, 'top'),
119100
'bottom': mspines.Spine.linear_spine(self, 'bottom'),
120101
'left': mspines.Spine.linear_spine(self, 'left'),
121102
'right': mspines.Spine.linear_spine(self, 'right')}
@@ -128,7 +109,7 @@ def _set_lim_and_transforms(self):
128109
"""
129110
rot = 30
130111

131-
#Get the standard transform setup from the Axes base class
112+
# Get the standard transform setup from the Axes base class
132113
Axes._set_lim_and_transforms(self)
133114

134115
# Need to put the skew in the middle, after the scale and limits,
@@ -150,6 +131,12 @@ def _set_lim_and_transforms(self):
150131
transforms.IdentityTransform()) +
151132
transforms.Affine2D().skew_deg(rot, 0)) + self.transAxes
152133

134+
@property
135+
def upper_xlim(self):
136+
pts = [[0., 1.], [1., 1.]]
137+
return self.transDataToAxes.inverted().transform(pts)[:, 0]
138+
139+
153140
# Now register the projection with matplotlib so the user can select
154141
# it.
155142
register_projection(SkewXAxes)
@@ -164,7 +151,7 @@ def test_set_line_coll_dash_image():
164151
ax.grid(True)
165152

166153
# An example of a slanted line at constant X
167-
l = ax.axvline(0, color='b')
154+
ax.axvline(0, color='b')
168155

169156

170157
@image_comparison(baseline_images=['skew_rects'], remove_text=True)

0 commit comments

Comments
 (0)