1
1
# -*- coding: utf-8 -*-
2
2
#
3
3
import helpers
4
+
5
+ import matplotlib .pyplot as plt
4
6
import pytest
5
7
6
8
# the picture 'lena.png' with origin='lower' is flipped upside-down.
7
9
# So it has to be upside-down in the pdf-file as well.
8
10
9
11
10
- # test for monochrome picture
11
- def plot1 ():
12
+ def plot_upper ():
12
13
from matplotlib import rcParams
13
- import matplotlib .pyplot as plt
14
- from PIL import Image
14
+ import matplotlib .image as mpimg
15
15
import os
16
16
17
17
this_dir = os .path .dirname (os .path .realpath (__file__ ))
18
- lena = Image . open (os .path .join (this_dir , 'lena.png' ))
19
- lena = lena . convert ( 'L' )
18
+ img = mpimg . imread (os .path .join (this_dir , 'lena.png' ))
19
+
20
20
dpi = rcParams ['figure.dpi' ]
21
- figsize = lena . size [0 ]/ dpi , lena . size [1 ]/ dpi
21
+ figsize = img . shape [0 ]/ dpi , img . shape [1 ]/ dpi
22
22
fig = plt .figure (figsize = figsize )
23
23
ax = plt .axes ([0 , 0 , 1 , 1 ], frameon = False )
24
24
ax .set_axis_off ()
25
- plt .imshow (lena , cmap = 'viridis' , origin = 'lower' )
25
+
26
+ plt .imshow (img , cmap = 'viridis' , origin = 'upper' )
27
+
26
28
# Set the current color map to HSV.
27
29
plt .hsv ()
28
30
plt .colorbar ()
29
31
return fig
30
32
31
33
32
- # test for rgb picture
33
- def plot2 ():
34
+ def plot_lower ():
34
35
from matplotlib import rcParams
35
- import matplotlib .pyplot as plt
36
- from PIL import Image
36
+ import matplotlib .image as mpimg
37
37
import os
38
38
39
39
this_dir = os .path .dirname (os .path .realpath (__file__ ))
40
- lena = Image .open (os .path .join (this_dir , 'lena.png' ))
40
+ img = mpimg .imread (os .path .join (this_dir , 'lena.png' ))
41
+
41
42
dpi = rcParams ['figure.dpi' ]
42
- figsize = lena .size [0 ] / dpi , lena .size [1 ] / dpi
43
+ figsize = img .shape [0 ] / dpi , img .shape [1 ] / dpi
44
+
43
45
fig = plt .figure (figsize = figsize )
44
46
ax = plt .axes ([0 , 0 , 1 , 1 ], frameon = False )
45
47
ax .set_axis_off ()
46
- plt .imshow (lena , cmap = 'viridis' , origin = 'lower' )
48
+ plt .imshow (img , cmap = 'viridis' , origin = 'lower' )
47
49
# Set the current color map to HSV.
48
50
plt .hsv ()
49
51
plt .colorbar ()
@@ -52,11 +54,16 @@ def plot2():
52
54
53
55
@pytest .mark .parametrize (
54
56
'plot, reference_phash' , [
55
- (plot1 , '455361ec211d72fb ' ),
56
- (plot2 , '7558d3b30f634b06 ' ),
57
+ (plot_upper , '75c3d36d1f090ba1 ' ),
58
+ (plot_lower , '7548d3b34f234b07 ' ),
57
59
]
58
60
)
59
61
def test (plot , reference_phash ):
60
62
phash = helpers .Phash (plot ())
61
63
assert phash .phash == reference_phash , phash .get_details ()
62
64
return
65
+
66
+
67
+ if __name__ == '__main__' :
68
+ plot_upper ()
69
+ plt .show ()
0 commit comments