1
1
from __future__ import (absolute_import , division , print_function ,
2
2
unicode_literals )
3
3
4
- import six
5
- from six .moves import xrange
8000
6
-
7
- from nose .tools import assert_equal , assert_true
4
+ from numpy .testing import assert_equal
8
5
from matplotlib import rcParams
9
6
from matplotlib .testing .decorators import image_comparison , cleanup
10
7
from matplotlib .axes import Axes
@@ -58,7 +55,7 @@ def test_figure():
58
55
fig = plt .figure ('today' )
59
56
ax = fig .add_subplot (111 )
60
57
ax .set_title (fig .get_label ())
61
- ax .plot (list ( xrange ( 5 ) ))
58
+ ax .plot (np . arange ( 5 ))
62
59
# plot red line in a different figure.
63
60
plt .figure ('tomorrow' )
64
61
plt .plot ([0 , 1 ], [1 , 0 ], 'r' )
@@ -84,44 +81,42 @@ def test_gca():
84
81
fig = plt .figure ()
85
82
86
83
ax1 = fig .add_axes ([0 , 0 , 1 , 1 ])
87
- assert_true ( fig .gca (projection = 'rectilinear' ) is ax1 )
88
- assert_true ( fig .gca () is ax1 )
84
+ assert fig .gca (projection = 'rectilinear' ) is ax1
85
+ assert fig .gca () is ax1
89
86
90
87
ax2 = fig .add_subplot (121 , projection = 'polar' )
91
- assert_true ( fig .gca () is ax2 )
92
- assert_true ( fig .gca (polar = True )is ax2 )
88
+ assert fig .gca () is ax2
89
+ assert fig .gca (polar = True )is ax2
93
90
94
91
ax3 = fig .add_subplot (122 )
95
- assert_true ( fig .gca () is ax3 )
92
+ assert fig .gca () is ax3
96
93
97
94
# the final request for a polar axes will end up creating one
98
95
# with a spec of 111.
99
96
with warnings .catch_warnings (record = True ) as w :
100
97
warnings .simplefilter ('always' )
101
98
# Changing the projection will throw a warning
102
- assert_true ( fig .gca (polar = True ) is not ax3 )
99
+ assert fig .gca (polar = True ) is not ax3
103
100
assert len (w ) == 1
104
- assert_true ( fig .gca (polar = True ) is not ax2 )
101
+ assert fig .gca (polar = True ) is not ax2
105
102
assert_equal (fig .gca ().get_geometry (), (1 , 1 , 1 ))
106
103
107
104
fig .sca (ax1 )
108
- assert_true ( fig .gca (projection = 'rectilinear' ) is ax1 )
109
- assert_true ( fig .gca () is ax1 )
105
+ assert fig .gca (projection = 'rectilinear' ) is ax1
106
+ assert fig .gca () is ax1
110
107
111
108
112
109
@image_comparison (baseline_images = ['figure_suptitle' ])
113
110
def test_suptitle ():
114
- fig = plt .figure ()
115
- ax = fig .add_subplot (1 , 1 , 1 )
111
+ fig , _ = plt .subplots ()
116
112
fig .suptitle ('hello' , color = 'r' )
117
113
fig .suptitle ('title' , color = 'g' , rotation = '30' )
118
114
119
115
120
116
@cleanup
121
117
def test_suptitle_fontproperties ():
122
118
from matplotlib .font_manager import FontProperties
123
- fig = plt .figure ()
124
- ax = fig .add_subplot (1 , 1 , 1 )
119
+ fig , ax = plt .subplots ()
125
120
fps = FontProperties (size = 'large' , weight = 'bold' )
126
121
txt = fig .suptitle ('fontprops title' , fontproperties = fps )
127
122
assert_equal (txt .get_fontsize (), fps .get_size_in_points ())
@@ -153,7 +148,7 @@ def test_too_many_figures():
153
148
with warnings .catch_warnings (record = True ) as w :
154
149
warnings .simplefilter ("always" )
155
150
for i in range (rcParams ['figure.max_open_warning' ] + 1 ):
156
- fig = plt .figure ()
151
+ plt .figure ()
157
152
assert len (w ) == 1
158
153
159
154
@@ -184,7 +179,7 @@ def _as_mpl_axes(self):
184
179
return MyAxes , {'myclass' : self }
185
180
186
181
fig = plt .figure ()
187
- ax = fig .add_subplot (1 , 1 , 1 , projection = MyClass ())
182
+ fig .add_subplot (1 , 1 , 1 , projection = MyClass ())
188
183
plt .close (fig )
189
184
190
185
@@ -230,8 +225,3 @@ def test_figaspect():
230
225
assert h / w == 0.5
231
226
w , h = plt .figaspect (np .zeros ((2 , 2 )))
232
227
assert h / w == 1
233
-
234
-
235
- if __name__ == "__main__" :
236
- import nose
237
- nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments