2
2
3
3
import numpy as np
4
4
import matplotlib .pyplot as plt
5
- from matplotlib .ticker import MultipleLocator , FuncFormatter
5
+ from matplotlib .ticker import AutoMinorLocator , MultipleLocator , FuncFormatter
6
6
7
- np .random .seed (123 )
7
+
8
+ np .random .seed (19680801 )
8
9
9
10
X = np .linspace (0.5 , 3.5 , 100 )
10
11
Y1 = 3 + np .cos (X )
11
12
Y2 = 1 + np .cos (1 + X / 0.75 )/ 2
12
13
Y3 = np .random .uniform (Y1 , Y2 , len (X ))
13
14
14
- fig = plt .figure (figsize = (8 , 8 ), facecolor = "w" )
15
+ fig = plt .figure (figsize = (8 , 8 ))
15
16
ax = fig .add_subplot (1 , 1 , 1 , aspect = 1 )
16
17
17
18
@@ -21,9 +22,9 @@ def minor_tick(x, pos):
21
22
return "%.2f" % x
22
23
23
24
ax .xaxis .set_major_locator (MultipleLocator (1.000 ))
24
- ax .xaxis .set_minor_locator (MultipleLocator ( 0.250 ))
25
+ ax .xaxis .set_minor_locator (AutoMinorLocator ( 4 ))
25
26
ax .yaxis .set_major_locator (MultipleLocator (1.000 ))
26
- ax .yaxis .set_minor_locator (MultipleLocator ( 0.250 ))
27
+ ax .yaxis .set_minor_locator (AutoMinorLocator ( 4 ))
27
28
ax .xaxis .set_minor_formatter (FuncFormatter (minor_tick ))
28
29
29
30
ax .set_xlim (0 , 4 )
@@ -38,13 +39,14 @@ def minor_tick(x, pos):
38
39
39
40
ax .plot (X , Y1 , c = (0.25 , 0.25 , 1.00 ), lw = 2 , label = "Blue signal" , zorder = 10 )
40
41
ax .plot (X , Y2 , c = (1.00 , 0.25 , 0.25 ), lw = 2 , label = "Red signal" )
41
- ax .scatter (X , Y3 , c = 'w' )
42
+ ax .plot (X , Y3 , linewidth = 0 ,
43
+ marker = 'o' , markerfacecolor = 'w' , markeredgecolor = 'k' )
42
44
43
- ax .set_title ("Anatomy of a figure" , fontsize = 20 )
45
+ ax .set_title ("Anatomy of a figure" , fontsize = 20 , verticalalignment = 'bottom' )
44
46
ax .set_xlabel ("X axis label" )
45
47
ax .set_ylabel ("Y axis label" )
46
48
47
- ax .legend (frameon = False )
49
+ ax .legend ()
48
50
49
51
50
52
def circle (x , y , radius = 0.15 ):
@@ -62,32 +64,32 @@ def text(x, y, text):
62
64
63
65
64
66
# Minor tick
65
- circle (0.50 , - .05 )
66
- text (0.50 , - 0.25 , "Minor tick label" )
67
+ circle (0.50 , - 0.10 )
68
+ text (0.50 , - 0.32 , "Minor tick label" )
67
69
68
70
# Major tick
69
- circle (4.00 , 2 .00 )
70
- text (4.00 , 1 .80 , "Major tick" )
71
+ circle (- 0.03 , 4 .00 )
72
+ text (0.03 , 3 .80 , "Major tick" )
71
73
72
74
# Minor tick
73
- circle (0.25 , 4.00 )
74
- text (0.25 , 3.80 , "Minor tick" )
75
+ circle (0.00 , 3.50 )
76
+ text (0.00 , 3.30 , "Minor tick" )
75
77
76
78
# Major tick label
77
- circle (- 0.05 , 3.00 )
78
- text (- 0.05 , 2.80 , "Major tick label" )
79
+ circle (- 0.15 , 3.00 )
80
+ text (- 0.15 , 2.80 , "Major tick label" )
79
81
80
82
# X Label
81
- circle (1.80 , - 0.22 )
82
- text (1.80 , - 0.4 , "X axis label" )
83
+ circle (1.80 , - 0.27 )
84
+ text (1.80 , - 0.45 , "X axis label" )
83
85
84
86
# Y Label
85
- circle (- 0.20 , 1.80 )
86
- text (- 0.20 , 1.6 , "Y axis label" )
87
+ circle (- 0.27 , 1.80 )
88
+ text (- 0.27 , 1.6 , "Y axis label" )
87
89
88
90
# Title
89
- circle (1.60 , 4.10 )
90
- text (1.60 , 3.9 , "Title" )
91
+ circle (1.60 , 4.13 )
92
+ text (1.60 , 3.93 , "Title" )
91
93
92
94
# Blue plot
93
95
circle (1.75 , 2.80 )
@@ -106,8 +108,8 @@ def text(x, y, text):
106
108
text (3.00 , 2.80 , "Grid" )
107
109
108
110
# Legend
109
- circle (3.70 , 3.75 )
110
- text (3.70 , 3.55 , "Legend" )
111
+ circle (3.70 , 3.80 )
112
+ text (3.70 , 3.60 , "Legend" )
111
113
112
114
# Axes
113
115
circle (0.5 , 0.5 )
0 commit comments