1
1
# -*- coding: utf-8 -*-
2
2
#
3
- desc = 'Regular plot with overlay text'
4
- phash = '370da93449d3f64c'
3
+ import helpers
5
4
5
+ import matplotlib .pyplot as plt
6
+ import numpy
6
7
7
- def plot ():
8
- from matplotlib import pyplot as pp
9
- import numpy as np
10
8
11
- fig = pp .figure ()
9
+ def plot ():
10
+ fig = plt .figure ()
12
11
13
- xxx = np .linspace (0 , 5 )
12
+ xxx = numpy .linspace (0 , 5 )
14
13
yyy = xxx ** 2
15
- pp .text (1 , 5 , 'test1' , size = 50 , rotation = 30. ,
14
+ plt .text (
15
+ 1 , 5 , 'test1' , size = 50 , rotation = 30. ,
16
16
ha = 'center' , va = 'bottom' , color = 'r' , style = 'italic' ,
17
17
weight = 'light' ,
18
- bbox = dict (boxstyle = 'round, pad=0.2' ,
19
- ec = (1. , 0.5 , 0.5 ),
20
- fc = (1. , 0.8 , 0.8 ),
21
- ls = 'dashdot'
22
- )
18
+ bbox = dict (
19
+ boxstyle = 'round, pad=0.2' ,
20
+ ec = (1. , 0.5 , 0.5 ),
21
+ fc = (1. , 0.8 , 0.8 ),
22
+ ls = 'dashdot'
23
+ )
23
24
)
24
- pp .text (3 , 6 , 'test2' , size = 50 , rotation = - 30. ,
25
+ plt .text (
26
+ 3 , 6 , 'test2' , size = 50 , rotation = - 30. ,
25
27
ha = 'center' , va = 'center' , color = 'b' , weight = 'bold' ,
26
- bbox = dict (boxstyle = 'square' ,
27
- ec = (1. , 0.5 , 0.5 ),
28
- fc = (1. , 0.8 , 0.8 ),
29
- )
28
+ bbox = dict (
29
+ boxstyle = 'square' ,
30
+ ec = (1. , 0.5 , 0.5 ),
31
+ fc = (1. , 0.8 , 0.8 ),
32
+ )
30
33
)
31
- pp .text (4 , 8 , 'test3' , size = 20 , rotation = 90.0 ,
34
+ plt .text (
35
+ 4 , 8 , 'test3' , size = 20 , rotation = 90.0 ,
32
36
ha = 'center' , va = 'center' , color = 'b' , weight = 'demi' ,
33
37
bbox = dict (
34
38
boxstyle = 'rarrow' ,
@@ -37,7 +41,8 @@ def plot():
37
41
fc = (1. , 0.8 , 0.8 ),
38
42
)
39
43
)
40
- pp .text (4 , 16 , 'test4' , size = 20 , rotation = 90.0 ,
44
+ plt .text (
45
+ 4 , 16 , 'test4' , size = 20 , rotation = 90.0 ,
41
46
ha = 'center' , va = 'center' , color = 'b' , weight = 'heavy' ,
42
47
bbox = dict (
43
48
boxstyle = 'larrow' ,
@@ -46,39 +51,54 @@ def plot():
46
51
fc = (1. , 0.8 , 0.8 ),
47
52
)
48
53
)
49
- pp .text (2 , 18 , 'test5' , size = 20 ,
54
+ plt .text (
55
+ 2 , 18 , 'test5' , size = 20 ,
50
56
ha = 'center' , va = 'center' , color = 'b' ,
51
57
bbox = dict (
52
58
boxstyle = 'darrow' ,
53
59
ec = (1. , 0.5 , 0.5 ),
54
60
fc = (1. , 0.8 , 0.8 ),
55
61
)
56
62
)
57
- pp .text (1 , 20 , 'test6' , size = 20 ,
63
+ plt .text (
64
+ 1 , 20 , 'test6' , size = 20 ,
58
65
ha = 'center' , va = 'center' , color = 'b' ,
59
66
bbox = dict (
60
67
boxstyle = 'circle' ,
61
68
ec = (1. , 0.5 , 0.5 ),
62
69
fc = (1. , 0.8 , 0.8 ),
63
70
)
64
71
)
65
- pp .text (3 , 23 , 'test7' , size = 20 ,
72
+ plt .text (
73
+ 3 , 23 , 'test7' , size = 20 ,
66
74
ha = 'center' , va = 'center' , color = 'b' ,
67
75
bbox = dict (
68
76
boxstyle = 'roundtooth' ,
69
77
ec = (1. , 0.5 , 0.5 ),
70
78
fc = (1. , 0.8 , 0.8 ),
71
79
)
72
80
)
73
- pp .text (3 , 20 , 'test8' , size = 20 ,
81
+ plt .text (
82
+ 3 , 20 , 'test8' , size = 20 ,
74
83
ha = 'center' , va = 'center' , color = 'b' ,
75
84
bbox = dict (
76
85
boxstyle = 'sawtooth' ,
77
86
ec = (1. , 0.5 , 0.5 ),
78
87
fc = (1. , 0.8 , 0.8 ),
79
88
)
80
89
)
81
- pp .plot (xxx , yyy , label = 'a graph' )
82
- pp .legend ()
90
+ plt .plot (xxx , yyy , label = 'a graph' )
91
+ plt .legend ()
83
92
84
93
return fig
94
+
95
+
96
+ def test ():
97
+ helpers .assert_phash (plot (), '370da93449d3f64c' )
98
+
99
+
100
+ if __name__ == '__main__' :
101
+ plot ()
102
+ plt .show ()
103
+ # phash, _, _, _, _, _, _ = helpers.compute_phash(plot2())
104
+ # print(phash)
0 commit comments