1
1
# -*- coding: utf-8 -*-
2
2
#
3
3
import helpers
4
+ from matplotlib import rcParams
5
+ from matplotlib import pyplot as pp
6
+ import pytest
7
+ import os
4
8
9
+ try :
10
+ from PIL import Image
11
+ except ImportError :
12
+ raise RuntimeError ('PIL must be installed to run this example' )
5
13
6
- def plot ():
7
- from matplotlib import rcParams
8
- from matplotlib import pyplot as pp
9
- import os
10
- try :
11
- from PIL import Image
12
- except ImportError :
13
- raise RuntimeError ('PIL must be installed to run this example' )
14
+ #the picture 'lena.png' with origin='lower' is flipped upside-down. So it has to be upside-down in the pdf-file as well.
15
+
16
+ def plot1 (): #test for monochrome picture
14
17
15
18
this_dir = os .path .dirname (os .path .realpath (__file__ ))
16
19
lena = Image .open (os .path .join (this_dir , 'lena.png' ))
@@ -26,6 +29,29 @@ def plot():
26
29
pp .colorbar ()
27
30
return fig
28
31
32
+ def plot2 (): #test for rgb picture
33
+
34
+ this_dir = os .path .dirname (os .path .realpath (__file__ ))
35
+ lena = Image .open (os .path .join (this_dir , 'lena.png' ))
36
+ dpi = rcParams ['figure.dpi' ]
37
+ figsize = lena .size [0 ] / dpi , lena .size [1 ] / dpi
38
+ fig = pp .figure (figsize = figsize )
39
+ ax = pp .axes ([0 , 0 , 1 , 1 ], frameon = False )
40
+ ax .set_axis_off ()
41
+ pp .imshow (lena , cmap = 'viridis' , origin = 'lower' )
42
+ # Set the current color map to HSV.
43
+ pp .hsv ()
44
+ pp .colorbar ()
45
+ return fig
46
+
47
+ @pytest .mark .parametrize (
48
+ 'plot, phash' , [
49
+ (plot1 , '455361ec211d72fb' ),
50
+ (plot2 , '7558d3b30f634b06' ),
51
+ ]
52
+ )
53
+
54
+ def test (plot , phash ):
55
+ helpers .assert_phash (plot (), phash )
56
+ return
29
57
30
- def test ():
31
- helpers .assert_phash (plot (), '455361ec211d72fb' )
0 commit comments