1
- import sys
2
-
3
1
import numpy as np
4
2
from numpy .testing import assert_array_almost_equal
5
3
import pytest
8
6
import matplotlib .transforms as mtransforms
9
7
10
8
11
- on_win = (sys .platform == 'win32' )
12
- on_mac = (sys .platform == 'darwin' )
13
-
14
-
15
9
def velocity_field ():
16
- Y , X = np .mgrid [- 3 :3 :100j , - 3 :3 :100j ]
10
+ Y , X = np .mgrid [- 3 :3 :100j , - 3 :3 :200j ]
17
11
U = - 1 - X ** 2 + Y
18
12
V = 1 + X - Y ** 2
19
13
return X , Y , U , V
20
14
21
15
22
16
def swirl_velocity_field ():
23
- x = np .linspace (- 3. , 3. , 100 )
17
+ x = np .linspace (- 3. , 3. , 200 )
24
18
y = np .linspace (- 3. , 3. , 100 )
25
19
X , Y = np .meshgrid (x , y )
26
20
a = 0.1
@@ -29,7 +23,8 @@ def swirl_velocity_field():
29
23
return x , y , U , V
30
24
31
25
32
- @image_comparison (['streamplot_startpoints' ], remove_text = True , style = 'mpl20' )
26
+ @image_comparison (['streamplot_startpoints' ], remove_text = True , style = 'mpl20' ,
27
+ tol = 0.513 )
33
28
def test_startpoints ():
34
29
X , Y , U , V = velocity_field ()
35
30
start_x = np .linspace (X .min (), X .max (), 10 )
@@ -39,51 +34,39 @@ def test_startpoints():
39
34
plt .plot (start_x , start_y , 'ok' )
40
35
41
36
42
- @image_comparison (['streamplot_colormap' ],
43
- tol = .04 , remove_text = True , style = 'mpl20' )
37
+ @image_comparison (['streamplot_colormap' ], remove_text = True , style = 'mpl20' )
44
38
def test_colormap ():
45
- # Remove this line when this test image is regenerated.
46
- plt .rcParams ['pcolormesh.snap' ] = False
47
-
48
39
X , Y , U , V = velocity_field ()
49
40
plt .streamplot (X , Y , U , V , color = U , density = 0.6 , linewidth = 2 ,
50
41
cmap = plt .cm .autumn )
51
42
plt .colorbar ()
52
43
53
44
54
- @image_comparison (['streamplot_linewidth' ], remove_text = True , style = 'mpl20' )
45
+ @image_comparison (['streamplot_linewidth' ], remove_text = True , style = 'mpl20' ,
46
+ tol = 0.002 )
55
47
def test_linewidth ():
56
48
X , Y , U , V = velocity_field ()
57
49
speed = np .hypot (U , V )
58
50
lw = 5 * speed / speed .max ()
59
- # Compatibility for old test image
60
- df = 25 / 30
61
51
ax = plt .figure ().subplots ()
62
- ax .set (xlim = (- 3.0 , 2.9999999999999947 ),
63
- ylim = (- 3.0000000000000004 , 2.9999999999999947 ))
64
- ax .streamplot (X , Y , U , V , density = [0.5 * df , 1. * df ], color = 'k' ,
65
- linewidth = lw )
52
+ ax .streamplot (X , Y , U , V , density = [0.5 , 1 ], color = 'k' , linewidth = lw )
66
53
67
54
68
55
@image_comparison (['streamplot_masks_and_nans' ],
69
- remove_text = True , style = 'mpl20' , tol = 0.04 if on_win else 0 )
56
+ remove_text = True , style = 'mpl20' )
70
57
def test_masks_and_nans ():
71
58
X , Y , U , V = velocity_field ()
72
59
mask = np .zeros (U .shape , dtype = bool )
73
- mask [40 :60 , 40 : 60 ] = 1
74
- U [:20 , :20 ] = np .nan
60
+ mask [40 :60 , 80 : 120 ] = 1
61
+ U [:20 , :40 ] = np .nan
75
62
U = np .ma .array (U , mask = mask )
76
- # Compatibility for old test image
77
63
ax = plt .figure ().subplots ()
78
- ax .set (xlim = (- 3.0 , 2.9999999999999947 ),
79
- ylim = (- 3.0000000000000004 , 2.9999999999999947 ))
80
64
with np .errstate (invalid = 'ignore' ):
81
65
ax .streamplot (X , Y , U , V , color = U , cmap = plt .cm .Blues )
82
66
83
67
84
68
@image_comparison (['streamplot_maxlength.png' ],
85
- remove_text = True , style = 'mpl20' ,
86
- tol = 0.002 if on_mac else 0 )
69
+ remove_text = True , style = 'mpl20' , tol = 0.302 )
87
70
def test_maxlength ():
88
71
x , y , U , V = swirl_velocity_field ()
89
72
ax = plt .figure ().subplots ()
@@ -95,7 +78,7 @@ def test_maxlength():
95
78
96
79
97
80
@image_comparison (['streamplot_direction.png' ],
98
- remove_text = True , style = 'mpl20' )
81
+ remove_text = True , style = 'mpl20' , tol = 0.056 )
99
82
def test_direction ():
100
83
x , y , U , V = swirl_velocity_field ()
101
84
plt .streamplot (x , y , U , V , integration_direction = 'backward' ,
0 commit comments