6
6
7
7
import unittest
8
8
9
- import numpy . testing as np_test
10
- from numpy .testing import assert_almost_equal , assert_array_equal
11
- from numpy . testing import assert_array_almost_equal
9
+ import numpy as np
10
+ from numpy .testing import ( assert_allclose , assert_almost_equal ,
11
+ assert_array_equal , assert_array_almost_equal )
12
12
import pytest
13
+
13
14
from matplotlib .transforms import (Affine2D , BlendedGenericTransform , Bbox ,
14
15
TransformedPath , TransformedPatchPath )
15
16
from matplotlib .path import Path
16
17
from matplotlib .scale import LogScale
17
18
from matplotlib .testing .decorators import cleanup , image_comparison
18
- import numpy as np
19
19
20
20
import matplotlib .transforms as mtrans
21
21
import matplotlib .pyplot as plt
@@ -76,8 +76,8 @@ def _as_mpl_transform(self, axes):
76
76
ax .set_xlim (0 , 100 )
77
77
ax .set_ylim (0 , 100 )
78
78
# assert that the top transform of the line is the scale transform.
79
- np . testing . assert_allclose (line .get_transform ()._a .get_matrix (),
80
- mtrans .Affine2D ().scale (10 ).get_matrix ())
79
+ assert_allclose (line .get_transform ()._a .get_matrix (),
80
+ mtrans .Affine2D ().scale (10 ).get_matrix ())
81
81
82
82
83
83
@image_comparison (baseline_images = ['pre_transform_data' ],
@@ -208,7 +208,7 @@ def test_clipping_of_log():
208
208
simplify = False )
209
209
210
210
tpoints , tcodes = list (zip (* result ))
211
- assert np . allclose (tcodes , [M , L , L , L , C ])
211
+ assert_allclose (tcodes , [M , L , L , L , C ])
212
212
213
213
214
214
class NonAffineForTest (mtrans .Transform ):
@@ -344,26 +344,26 @@ def test_affine_simplification(self):
344
344
dtype = np .float64 )
345
345
346
346
# check we have the expected results from doing the affine part only
347
- np_test . assert_array_almost_equal (na_pts , na_expected )
347
+ assert_array_almost_equal (na_pts , na_expected )
348
348
# check we have the expected results from a full transformation
349
- np_test . assert_array_almost_equal (all_pts , all_expected )
349
+ assert_array_almost_equal (all_pts , all_expected )
350
350
# check we have the expected results from doing the transformation in
351
351
# two steps
352
- np_test . assert_array_almost_equal (self .stack1 .transform_affine (na_pts ),
353
- all_expected )
352
+ assert_array_almost_equal (self .stack1 .transform_affine (na_pts ),
353
+ all_expected )
354
354
# check that getting the affine transformation first, then fully
355
355
# transforming using that yields the same result as before.
356
- np_test . assert_array_almost_equal (
357
- self . stack1 . get_affine (). transform ( na_pts ), all_expected )
356
+ assert_array_almost_equal (self . stack1 . get_affine (). transform ( na_pts ),
357
+ all_expected )
358
358
359
359
# check that the affine part of stack1 & stack2 are equivalent
360
360
# (i.e. the optimization is working)
361
361
expected_result = (self .ta2 + self .ta3 ).get_matrix ()
362
362
result = self .stack1 .get_affine ().get_matrix ()
363
- np_test . assert_array_equal (expected_result , result )
363
+ assert_array_equal (expected_result , result )
364
364
365
365
result = self .stack2 .get_affine ().get_matrix ()
366
- np_test . assert_array_equal (expected_result , result )
366
+ assert_array_equal (expected_result , result )
367
367
368
368
369
369
class TestTransformPlotInterface (unittest .TestCase ):
@@ -374,35 +374,35 @@ def test_line_extent_axes_coords(self):
374
374
# a simple line in axes coordinates
375
375
ax = plt .axes ()
376
376
ax .plot ([0.1 , 1.2 , 0.8 ], [0.9 , 0.5 , 0.8 ], transform = ax .transAxes )
377
- np . testing . assert_array_equal (ax .dataLim .get_points (),
378
- np .array ([[np .inf , np .inf ],
379
- [- np .inf , - np .inf ]]))
377
+ assert_array_equal (ax .dataLim .get_points (),
378
+ np .array ([[np .inf , np .inf ],
379
+ [- np .inf , - np .inf ]]))
380
380
381
381
def test_line_extent_data_coords (self ):
382
382
# a simple line in data coordinates
383
383
ax = plt .axes ()
384
384
ax .plot ([0.1 , 1.2 , 0.8 ], [0.9 , 0.5 , 0.8 ], transform = ax .transData )
385
- np . testing . assert_array_equal (ax .dataLim .get_points (),
386
- np .array ([[0.1 , 0.5 ], [1.2 , 0.9 ]]))
385
+ assert_array_equal (ax .dataLim .get_points (),
386
+ np .array ([[0.1 , 0.5 ], [1.2 , 0.9 ]]))
387
387
388
388
def test_line_extent_compound_coords1 (self ):
389
389
# a simple line in data coordinates in the y component, and in axes
390
390
# coordinates in the x
391
391
ax = plt .axes ()
392
392
trans = mtrans .blended_transform_factory (ax .transAxes , ax .transData )
393
393
ax .plot ([0.1 , 1.2 , 0.8 ], [35 , - 5 , 18 ], transform = trans )
394
- np . testing . assert_array_equal (ax .dataLim .get_points (),
395
- np .array ([[np .inf , - 5. ],
396
- [- np .inf , 35. ]]))
394
+ assert_array_equal (ax .dataLim .get_points (),
395
+ np .array ([[np .inf , - 5. ],
396
+ [- np .inf , 35. ]]))
397
397
plt .close ()
398
398
399
399
def test_line_extent_predata_transform_coords (self ):
400
400
# a simple line in (offset + data) coordinates
401
401
ax = plt .axes ()
402
402
trans = mtrans .Affine2D ().scale (10 ) + ax .transData
403
403
ax .plot ([0.1 , 1.2 , 0.8 ], [35 , - 5 , 18 ], transform = trans )
404
- np . testing . assert_array_equal (ax .dataLim .get_points (),
405
- np .array ([[1. , - 50. ], [12. , 350. ]]))
404
+ assert_array_equal (ax .dataLim .get_points (),
405
+ np .array ([[1. , - 50. ], [12. , 350. ]]))
406
406
plt .close ()
407
407
408
408
def test_line_extent_compound_coords2 (self ):
@@ -412,27 +412,24 @@ def test_line_extent_compound_coords2(self):
412
412
trans = mtrans .blended_transform_factory (
413
413
ax .transAxes , mtrans .Affine2D ().scale (10 ) + ax .transData )
414
414
ax .plot ([0.1 , 1.2 , 0.8 ], [35 , - 5 , 18 ], transform = trans )
415
- np .testing .assert_array_equal (
416
- ax .dataLim .get_points (),
417
- np .array ([[np .inf , - 50. ], [- np .inf , 350. ]]))
415
+ assert_array_equal (ax .dataLim .get_points (),
416
+ np .array ([[np .inf , - 50. ], [- np .inf , 350. ]]))
418
417
plt .close ()
419
418
420
419
def test_line_extents_affine (self ):
421
420
ax = plt .axes ()
422
421
offset = mtrans .Affine2D ().translate (10 , 10 )
423
422
plt .plot (list (xrange (10 )), transform = offset + ax .transData )
424
- expeted_data_lim = np .array ([[0. , 0. ], [9. , 9. ]]) + 10
425
- np .testing .assert_array_almost_equal (ax .dataLim .get_points (),
426
- expeted_data_lim )
423
+ expected_data_lim = np .array ([[0. , 0. ], [9. , 9. ]]) + 10
424
+ assert_array_almost_equal (ax .dataLim .get_points (), expected_data_lim )
427
425
428
426
def test_line_extents_non_affine (self ):
429
427
ax = plt .axes ()
430
428
offset = mtrans .Affine2D ().translate (10 , 10 )
431
429
na_offset = NonAffineForTest (mtrans .Affine2D ().translate (10 , 10 ))
432
430
plt .plot (list (xrange (10 )), transform = offset + na_offset + ax .transData )
433
- expeted_data_lim = np .array ([[0. , 0. ], [9. , 9. ]]) + 20
434
- np .testing .assert_array_almost_equal (ax .dataLim .get_points (),
435
- expeted_data_lim )
431
+ expected_data_lim = np .array ([[0. , 0. ], [9. , 9. ]]) + 20
432
+ assert_array_almost_equal (ax .dataLim .get_points (), expected_data_lim )
436
433
437
434
def test_pathc_extents_non_affine (self ):
438
435
ax = plt .axes ()
@@ -442,19 +439,17 @@ def test_pathc_extents_non_affine(self):
442
439
patch = mpatches .PathPatch (pth ,
443
440
transform = offset + na_offset + ax .transData )
444
441
ax .add_patch (patch )
445
- expeted_data_lim = np .array ([[0. , 0. ], [10. , 10. ]]) + 20
446
- np .testing .assert_array_almost_equal (ax .dataLim .get_points (),
447
- expeted_data_lim )
442
+ expected_data_lim = np .array ([[0. , 0. ], [10. , 10. ]]) + 20
443
+ assert_array_almost_equal (ax .dataLim .get_points (), expected_data_lim )
448
444
449
445
def test_pathc_extents_affine (self ):
450
446
ax = plt .axes ()
451
447
offset = mtrans .Affine2D ().translate (10 , 10 )
452
448
pth = mpath .Path (np .array ([[0 , 0 ], [0 , 10 ], [10 , 10 ], [10 , 0 ]]))
453
449
patch = mpatches .PathPatch (pth , transform = offset + ax .transData )
454
450
ax .add_patch (patch )
455
- expeted_data_lim = np .array ([[0. , 0. ], [10. , 10. ]]) + 10
456
- np .testing .assert_array_almost_equal (ax .dataLim .get_points (),
457
- expeted_data_lim )
451
+ expected_data_lim = np .array ([[0. , 0. ], [10. , 10. ]]) + 10
452
+ assert_array_almost_equal (ax .dataLim .get_points (), expected_data_lim )
458
453
459
454
def test_line_extents_for_non_affine_transData (self ):
460
455
ax = plt .axes (projection = 'polar' )
@@ -465,9 +460,8 @@ def test_line_extents_for_non_affine_transData(self):
465
460
# the data lim of a polar plot is stored in coordinates
466
461
# before a transData transformation, hence the data limits
467
462
# are not what is being shown on the actual plot.
468
- expeted_data_lim = np .array ([[0. , 0. ], [9. , 9. ]]) + [0 , 10 ]
469
- np .testing .assert_array_almost_equal (ax .dataLim .get_points (),
470
- expeted_data_lim )
463
+ expected_data_lim = np .array ([[0. , 0. ], [9. , 9. ]]) + [0 , 10 ]
464
+ assert_array_almost_equal (ax .dataLim .get_points (), expected_data_lim )
471
465
472
466
473
467
def assert_bbox_eq (bbox1 , bbox2 ):
@@ -585,19 +579,20 @@ def test_transformed_path():
585
579
586
580
trans = mtrans .Affine2D ()
587
581
trans_path = TransformedPath (path , trans )
588
- assert np .allclose (trans_path .get_fully_transformed_path ().vertices ,
589
- points )
582
+ assert_allclose (trans_path .get_fully_transformed_path ().vertices , points )
590
583
591
584
# Changing the transform should change the result.
592
585
r2 = 1 / np .sqrt (2 )
593
586
trans .rotate (np .pi / 4 )
594
- assert np .allclose (trans_path .get_fully_transformed_path ().vertices ,
595
- [(0 , 0 ), (r2 , r2 ), (0 , 2 * r2 ), (- r2 , r2 )])
587
+ assert_allclose (trans_path .get_fully_transformed_path ().vertices ,
588
+ [(0 , 0 ), (r2 , r2 ), (0 , 2 * r2 ), (- r2 , r2 )],
589
+ atol = 1e-15 )
596
590
597
591
# Changing the path does not change the result (it's cached).
598
592
path .points = [(0 , 0 )] * 4
599
- assert np .allclose (trans_path .get_fully_transformed_path ().vertices ,
600
- [(0 , 0 ), (r2 , r2 ), (0 , 2 * r2 ), (- r2 , r2 )])
593
+ assert_allclose (trans_path .get_fully_transformed_path ().vertices ,
594
+ [(0 , 0 ), (r2 , r2 ), (0 , 2 * r2 ), (- r2 , r2 )],
595
+ atol = 1e-15 )
601
596
602
597
603
598
def test_transformed_patch_path ():
@@ -609,11 +604,9 @@ def test_transformed_patch_path():
609
604
610
605
# Changing the transform should change the result.
611
606
trans .scale (2 )
612
- assert np .allclose (tpatch .get_fully_transformed_path ().vertices ,
613
- points * 2 )
607
+ assert_allclose (tpatch .get_fully_transformed_path ().vertices , points * 2 )
614
608
615
609
# Changing the path should change the result (and cancel out the scaling
616
610
# from the transform).
617
611
patch .set_radius (0.5 )
618
- assert np .allclose (tpatch .get_fully_transformed_path ().vertices ,
619
- points )
612
+ assert_allclose (tpatch .get_fully_transformed_path ().vertices , points )
0 commit comments