5
5
6
6
import datetime
7
7
8
- import dateutil .tz as dutz
8
+ import dateutil .tz
9
9
10
10
import numpy as np
11
11
from numpy import ma
@@ -498,8 +498,7 @@ def test_polar_coord_annotations():
498
498
# native coordinate system ('data') is cartesian, so you need to
499
499
# specify the xycoords and textcoords as 'polar' if you want to
500
500
# use (theta, radius)
501
- from matplotlib .patches import Ellipse
502
- el = Ellipse ((0 , 0 ), 10 , 20 , facecolor = 'r' , alpha = 0.5 )
501
+ el = mpatches .Ellipse ((0 , 0 ), 10 , 20 , facecolor = 'r' , alpha = 0.5 )
503
502
504
503
fig = plt .figure ()
505
504
ax = fig .add_subplot (111 , aspect = 'equal' )
@@ -548,12 +547,11 @@ def test_polar_alignment():
548
547
549
548
@image_comparison (['fill_units.png' ], savefig_kwarg = {'dpi' : 60 })
550
549
def test_fill_units ():
551
- from datetime import datetime
552
550
import matplotlib .testing .jpl_units as units
553
551
units .register ()
554
552
555
553
# generate some data
556
- t = units .Epoch ("ET" , dt = datetime (2009 , 4 , 27 ))
554
+ t = units .Epoch ("ET" , dt = datetime . datetime (2009 , 4 , 27 ))
557
555
value = 10.0 * units .deg
558
556
day = units .Duration ("ET" , 24.0 * 60.0 * 60.0 )
559
557
@@ -854,13 +852,12 @@ def test_aitoff_proj():
854
852
855
853
@image_comparison (['axvspan_epoch' ])
856
854
def test_axvspan_epoch ():
857
- from datetime import datetime
858
855
import matplotlib .testing .jpl_units as units
859
856
units .register ()
860
857
861
858
# generate some data
862
- t0 = units .Epoch ("ET" , dt = datetime (2009 , 1 , 20 ))
863
- tf = units .Epoch ("ET" , dt = datetime (2009 , 1 , 21 ))
859
+ t0 = units .Epoch ("ET" , dt = datetime . datetime (2009 , 1 , 20 ))
860
+ tf = units .Epoch ("ET" , dt = datetime . datetime (2009 , 1 , 21 ))
864
861
dt = units .Duration ("ET" , units .day .convert ("sec" ))
865
862
866
863
ax = plt .gca ()
@@ -870,13 +867,12 @@ def test_axvspan_epoch():
870
867
871
868
@image_comparison (['axhspan_epoch' ])
872
869
def test_axhspan_epoch ():
873
- from datetime import datetime
874
870
import matplotlib .testing .jpl_units as units
875
871
units .register ()
876
872
877
873
# generate some data
878
- t0 = units .Epoch ("ET" , dt = datetime (2009 , 1 , 20 ))
879
- tf = units .Epoch ("ET" , dt = datetime (2009 , 1 , 21 ))
874
+ t0 = units .Epoch ("ET" , dt = datetime . datetime (2009 , 1 , 20 ))
875
+ tf = units .Epoch ("ET" , dt = datetime . datetime (2009 , 1 , 21 ))
880
876
dt = units .Duration ("ET" , units .day .convert ("sec" ))
881
877
882
878
ax = plt .gca ()
@@ -1013,11 +1009,10 @@ def test_imshow_clip():
1013
1009
1014
1010
c = ax .contour (r , [N / 4 ])
1015
1011
x = c .collections [0 ]
1016
- clipPath = x .get_paths ()[0 ]
1017
- clipTransform = x .get_transform ()
1012
+ clip_path = x .get_paths ()[0 ]
1013
+ clip_transform = x .get_transform ()
1018
1014
1019
- from matplotlib .transforms import TransformedPath
1020
- clip_path = TransformedPath (clipPath , clipTransform )
1015
+ clip_path = mtransforms .TransformedPath (clip_path , clip_transform )
1021
1016
1022
1017
# Plot the image clipped by the contour
1023
1018
ax .imshow (r , clip_path = clip_path )
@@ -1039,12 +1034,9 @@ def test_imshow_norm_vminvmax(fig_test, fig_ref):
1039
1034
@image_comparison (['polycollection_joinstyle' ], remove_text = True )
1040
1035
def test_polycollection_joinstyle ():
1041
1036
# Bug #2890979 reported by Matthew West
1042
-
1043
- from matplotlib import collections as mcoll
1044
-
1045
1037
fig , ax = plt .subplots ()
1046
1038
verts = np .array ([[1 , 1 ], [1 , 2 ], [2 , 2 ], [2 , 1 ]])
1047
- c = mcoll .PolyCollection ([verts ], linewidths = 40 )
1039
+ c = mpl . collections .PolyCollection ([verts ], linewidths = 40 )
1048
1040
ax .add_collection (c )
1049
1041
ax .set_xbound (0 , 3 )
1050
1042
ax .set_ybound (0 , 3 )
@@ -1308,7 +1300,6 @@ def test_canonical():
1308
1300
1309
1301
@image_comparison (['arc_angles.png' ], remove_text = True , style = 'default' )
1310
1302
def test_arc_angles ():
1311
- from matplotlib import patches
1312
1303
# Ellipse parameters
1313
1304
w = 2
1314
1305
h = 1
@@ -1320,8 +1311,8 @@ def test_arc_angles():
1320
1311
theta2 = i * 360 / 9
1321
1312
theta1 = theta2 - 45
1322
1313
1323
- ax .add_patch (patches .Ellipse (centre , w , h , alpha = 0.3 ))
1324
- ax .add_patch (patches .Arc (centre , w , h , theta1 = theta1 , theta2 = theta2 ))
1314
+ ax .add_patch (mpatches .Ellipse (centre , w , h , alpha = 0.3 ))
1315
+ ax .add_patch (mpatches .Arc (centre , w , h , theta1 = theta1 , theta2 = theta2 ))
1325
1316
# Straight lines intersecting start and end of arc
1326
1317
ax .plot ([scale * np .cos (np .deg2rad (theta1 )) + centre [0 ],
1327
1318
centre [0 ],
@@ -1343,7 +1334,6 @@ def test_arc_angles():
1343
1334
1344
1335
@image_comparison (['arc_ellipse' ], remove_text = True )
1345
1336
def test_arc_ellipse ():
1346
- from matplotlib import patches
1347
1337
xcenter , ycenter = 0.38 , 0.52
1348
1338
width , height = 1e-1 , 3e-1
1349
1339
angle = - 30
@@ -1366,15 +1356,15 @@ def test_arc_ellipse():
1366
1356
ax .fill (x , y , alpha = 0.2 , facecolor = 'yellow' , edgecolor = 'yellow' ,
1367
1357
linewidth = 1 , zorder = 1 )
1368
1358
1369
- e1 = patches .Arc ((xcenter , ycenter ), width , height ,
1370
- angle = angle , linewidth = 2 , fill = False , zorder = 2 )
1359
+ e1 = mpatches .Arc ((xcenter , ycenter ), width , height ,
1360
+ angle = angle , linewidth = 2 , fill = False , zorder = 2 )
1371
1361
1372
1362
ax .add_patch (e1 )
1373
1363
1374
1364
ax = fig .add_subplot (212 , aspect = 'equal' )
1375
1365
ax.fill (x , y , alpha = 0.2 , facecolor = 'green' , edgecolor = 'green' , zorder = 1 )
1376
- e2 = patches .Arc ((xcenter , ycenter ), width , height ,
1377
- angle = angle , linewidth = 2 , fill = False , zorder = 2 )
1366
+ e2 = mpatches .Arc ((xcenter , ycenter ), width , height ,
1367
+ angle = angle , linewidth = 2 , fill = False , zorder = 2 )
1378
1368
1379
1369
ax .add_patch (e2 )
1380
1370
@@ -2093,23 +2083,20 @@ def test_scatter_c(self, c_case, re_key):
2093
2083
def get_next_color ():
2094
2084
return 'blue' # currently unused
2095
2085
2096
- from matplotlib .axes import Axes
2097
-
2098
2086
xsize = 4
2099
-
2100
2087
# Additional checking of *c* (introduced in #11383).
2101
2088
REGEXP = {
2102
2089
"shape" : "^'c' argument has [0-9]+ elements" , # shape mismatch
2103
2090
"conversion" : "^'c' argument must be a color" , # bad vals
2104
2091
}
2105
2092
2106
2093
if re_key is None :
2107
- Axes ._parse_scatter_color_args (
2094
+ mpl . axes . Axes ._parse_scatter_color_args (
2108
2095
c = c_case , edgecolors = "black" , kwargs = {}, xsize = xsize ,
2109
2096
get_next_color_func = get_next_color )
2110
2097
else :
2111
2098
with pytest .raises (ValueError , match = REGEXP [re_key ]):
2112
- Axes ._parse_scatter_color_args (
2099
+ mpl . axes . Axes ._parse_scatter_color_args (
2113
2100
c = c_case , edgecolors = "black" , kwargs = {}, xsize = xsize ,
2114
2101
get_next_color_func = get_next_color )
2115
2102
@@ -2137,8 +2124,7 @@ def test_parse_scatter_color_args(params, expected_result):
2137
2124
def get_next_color ():
2138
2125
return 'blue' # currently unused
2139
2126
2140
- from matplotlib .axes import Axes
2141
- c , colors , _edgecolors = Axes ._parse_scatter_color_args (
2127
+ c , colors , _edgecolors = mpl .axes .Axes ._parse_scatter_color_args (
2142
2128
* params , get_next_color_func = get_next_color )
2143
2129
assert c == expected_result .c
2144
2130
assert_allclose (colors , expected_result .colors )
@@ -2164,19 +2150,17 @@ def test_parse_scatter_color_args_edgecolors(kwargs, expected_edgecolors):
2164
2150
def get_next_color ():
2165
2151
return 'blue' # currently unused
2166
2152
2167
- from matplotlib .axes import Axes
2168
2153
c = kwargs .pop ('c' , None )
2169
2154
edgecolors = kwargs .pop ('edgecolors' , None )
2170
2155
_ , _ , result_edgecolors = \
2171
- Axes ._parse_scatter_color_args (c , edgecolors , kwargs , xsize = 2 ,
2172
- get_next_color_func = get_next_color )
2156
+ mpl . axes . Axes ._parse_scatter_color_args (
2157
+ c , edgecolors , kwargs , xsize = 2 , get_next_color_func = get_next_color )
2173
2158
assert result_edgecolors == expected_edgecolors
2174
2159
2175
2160
2176
2161
def test_as_mpl_axes_api ():
2177
2162
# tests the _as_mpl_axes api
2178
2163
from matplotlib .projections .polar import PolarAxes
2179
- import matplotlib .axes as maxes
2180
2164
2181
2165
class Polar :
2182
2166
def __init__ (self ):
@@ -2200,7 +2184,7 @@ def _as_mpl_axes(self):
2200
2184
2201
2185
# testing axes creation with gca
2202
2186
ax = plt .gca (projection = prj )
2203
- assert type (ax ) == maxes ._subplots .subplot_class_factory (PolarAxes )
2187
+ assert type (ax ) == mpl . axes ._subplots .subplot_class_factory (PolarAxes )
2204
2188
ax_via_gca = plt .gca (projection = prj )
2205
2189
assert ax_via_gca is ax
2206
2190
# try getting the axes given a different polar projection
@@ -2221,7 +2205,7 @@ def _as_mpl_axes(self):
2221
2205
2222
2206
# testing axes creation with subplot
2223
2207
ax = plt .subplot (121 , projection = prj )
2224
- assert type (ax ) == maxes ._subplots .subplot_class_factory (PolarAxes )
2208
+ assert type (ax ) == mpl . axes ._subplots .subplot_class_factory (PolarAxes )
2225
2209
plt .close ()
2226
2210
2227
2211
@@ -3324,14 +3308,10 @@ def test_stem_args():
3324
3308
3325
3309
def test_stem_dates ():
3326
3310
fig , ax = plt .subplots (1 , 1 )
3327
- from dateutil import parser
3328
- x = parser .parse ("2013-9-28 11:00:00" )
3329
- y = 100
3330
-
3331
- x1 = parser .parse ("2013-9-28 12:00:00" )
3332
- y1 = 200
3333
-
3334
- ax .stem ([x , x1 ], [y , y1 ], "*-" , use_line_collection = True )
3311
+ xs = [dateutil .parser .parse ("2013-9-28 11:00:00" ),
3312
+ dateutil .parser .parse ("2013-9-28 12:00:00" )]
3313
+ ys = [100 , 200 ]
3314
+ ax .stem (xs , ys , "*-" , use_line_collection = True )
3335
3315
3336
3316
3337
3317
@image_comparison (['hist_stacked_stepfilled_alpha' ])
@@ -3977,22 +3957,19 @@ def test_step_linestyle():
3977
3957
3978
3958
@image_comparison (['mixed_collection' ], remove_text = True )
3979
3959
def test_mixed_collection ():
3980
- from matplotlib import patches
3981
- from matplotlib import collections
3982
-
3983
3960
# First illustrate basic pyplot interface, using defaults where possible.
3984
3961
fig = plt .figure ()
3985
3962
ax = fig .add_subplot (1 , 1 , 1 )
3986
3963
3987
- c = patches .Circle ((8 , 8 ), radius = 4 , facecolor = 'none' , edgecolor = 'green' )
3964
+ c = mpatches .Circle ((8 , 8 ), radius = 4 , facecolor = 'none' , edgecolor = 'green' )
3988
3965
3989
3966
# PDF can optimize this one
3990
- p1 = collections .PatchCollection ([c ], match_original = True )
3967
+ p1 = mpl . collections .PatchCollection ([c ], match_original = True )
3991
3968
p1 .set_offsets ([[0 , 0 ], [24 , 24 ]])
3992
3969
p1 .set_linewidths ([1 , 5 ])
3993
3970
3994
3971
# PDF can't optimize this one, because the alpha of the edge changes
3995
- p2 = collections .PatchCollection ([c ], match_original = True )
3972
+ p2 = mpl . collections .PatchCollection ([c ], match_original = True )
3996
3973
p2 .set_offsets ([[48 , 0 ], [- 32 , - 16 ]])
3997
3974
p2 .set_linewidths ([1 , 5 ])
3998
3975
p2 .set_edgecolors ([[0 , 0 , 0.1 , 1.0 ], [0 , 0 , 0.1 , 0.5 ]])
@@ -5960,7 +5937,7 @@ def test_bar_uint8():
5960
5937
def test_date_timezone_x ():
5961
5938
# Tests issue 5575
5962
5939
time_index = [datetime .datetime (2016 , 2 , 22 , hour = x ,
5963
- tzinfo = dutz .gettz ('Canada/Eastern' ))
5940
+ tzinfo = dateutil . tz .gettz ('Canada/Eastern' ))
5964
5941
for x in range (3 )]
5965
5942
5966
5943
# Same Timezone
@@ -5977,7 +5954,7 @@ def test_date_timezone_x():
5977
5954
def test_date_timezone_y ():
5978
5955
# Tests issue 5575
5979
5956
time_index = [datetime .datetime (2016 , 2 , 22 , hour = x ,
5980
- tzinfo = dutz .gettz ('Canada/Eastern' ))
5957
+ tzinfo = dateutil . tz .gettz ('Canada/Eastern' ))
5981
5958
for x in range (3 )]
5982
5959
5983
5960
# Same Timezone
@@ -6416,9 +6393,6 @@ def test_spines_properbbox_after_zoom():
6416
6393
6417
6394
6418
6395
def test_cartopy_backcompat ():
6419
- import matplotlib
6420
- import matplotlib .axes
6421
- import matplotlib .axes ._subplots
6422
6396
6423
6397
class Dummy (matplotlib .axes .Axes ):
6424
6398
...
0 commit comments