26
26
Y3 = np .random .uniform (Y1 , Y2 , len (X ))
27
27
28
28
fig = plt .figure (figsize = (8 , 8 ), facecolor = '1' )
29
- marg = 0.13
29
+ marg = 0.15
30
30
ax = fig .add_axes ([marg , marg , 1 - 1.8 * marg , 1 - 1.8 * marg ], aspect = 1 ,
31
31
facecolor = '1' )
32
32
@@ -68,7 +68,7 @@ def minor_tick(x, pos):
68
68
# Annotate the figure
69
69
70
70
71
- def circle (x , y , radius = 0.15 ):
71
+ def just_circle (x , y , radius = 0.15 ):
72
72
c = Circle ((x , y ), radius , clip_on = False , zorder = 10 , linewidth = 2.5 ,
73
73
edgecolor = royal_blue + [0.6 ], facecolor = 'none' ,
74
74
path_effects = [withStroke (linewidth = 7 , foreground = (1 , 1 , 1 , 1 ))])
@@ -82,70 +82,69 @@ def text(x, y, text):
82
82
path_effects = [withStroke (linewidth = 7 , foreground = (1 , 1 , 1 , 1 ))])
83
83
84
84
85
- # Minor tick
86
- circle (3.25 , - 0.10 )
87
- text (3.25 , - 0.32 , "Minor tick label" )
85
+ def code (x , y , text ):
86
+ ax .text (x , y , text , zorder = 100 ,
87
+ ha = 'center' , va = 'top' , weight = 'normal' , color = '0.0' ,
88
+ fontfamily = 'Courier New' , fontsize = 'medium' ,
89
+ path_effects = [withStroke (linewidth = 7 , foreground = (1 , 1 , 1 , 1 ))])
90
+
91
+
92
+ def circle (x , y , txt , cde , radius = 0.15 ):
93
+ just_circle (x , y , radius = radius )
94
+ text (x , y - 0.2 , txt )
95
+ code (x , y - 0.33 , cde )
96
+
97
+ # Minor tick label
98
+ circle (3.25 , - 0.10 , "Minor tick label" ,
99
+ "ax.xaxis.set_minor_formatter" )
88
100
89
101
# Major tick
90
- circle (- 0.03 , 4.00 )
91
- text (0.03 , 3.80 , "Major tick" )
102
+ circle (- 0.03 , 1.05 , "Major tick" , "ax.yaxis.set_major_locator" )
92
103
93
104
# Minor tick
94
- circle ( 0.00 , 3.50 )
95
- text (0.00 , 3.30 , "Minor tick" )
105
+ y = 3.75
106
+ circle (0.00 , 3.75 , "Minor tick" , "ax.yaxis.set_minor_locator " )
96
107
97
108
# Major tick label
98
- circle (- 0.15 , 3.00 )
99
- text (- 0.15 , 2.80 , "Major tick label" )
109
+ circle (- 0.15 , 3.00 , "Major tick label" , "ax.yaxis.set_major_formatter" )
100
110
101
111
# X Label
102
- circle (1.90 , - 0.27 )
103
- text (1.90 , - 0.47 , "xlabel" )
112
+ circle (1.90 , - 0.32 , "xlabel" , "ax.set_xlabel" )
104
113
105
114
# Y Label
106
- circle (- 0.27 , 1.75 )
107
- text (- 0.27 , 1.55 , "ylabel" )
115
+ circle (- 0.27 , 1.68 , "ylabel" , "ax.set_ylabel" )
108
116
109
117
# Title
110
- circle (1.58 , 4.13 )
111
- text (1.58 , 3.93 , "Title" )
118
+ circle (1.58 , 4.13 , "Title" , "ax.set_title" )
112
119
113
120
# Blue plot
114
- circle (1.75 , 2.80 )
115
- text (1.75 , 2.60 , "Line\n (line plot)" )
121
+ circle (1.75 , 2.80 , "Line" , "ax.plot" )
116
122
117
123
# Scatter plot
118
- circle (2.25 , 1.54 )
119
- text (2.25 , 1.34 , "Markers\n (scatter plot)" )
124
+ circle (2.25 , 1.54 , "Markers" , "ax.scatter" )
120
125
121
126
# Grid
122
- circle (3.00 , 3.00 )
123
- text (3.00 , 2.80 , "Grid" )
127
+ circle (3.00 , 3.00 , "Grid" , "ax.grid" )
124
128
125
129
# Legend
126
- circle (3.60 , 3.65 )
127
- text (3.60 , 3.45 , "Legend" )
130
+ circle (3.60 , 3.65 , "Legend" , "ax.legend" )
128
131
129
132
# Axes
130
- circle (0.5 , 0.5 )
131
- text (0.5 , 0.3 , "Axes" )
133
+ circle (2.5 , 0.55 , "Axes" , "fig.subplots" )
132
134
133
135
# Figure
134
- circle (4.185 , 4.3 )
135
- text (4.185 , 4.1 , "Figure" )
136
+ circle (4.185 , 4.3 , "Figure" , "plt.figure" )
136
137
137
- # Axis
138
- circle (0.65 , 0.01 )
139
- text (0.65 , - 0.2 , "x Axis" )
138
+ # x Axis
139
+ circle (0.65 , 0.01 , "x Axis" , "ax.xaxis" )
140
140
141
- # Axis
142
- circle (0 , 0.7 )
143
- text (0 , 0.7 - 0.2 , "y Axis" )
141
+ # y Axis
142
+ circle (0 , 0.44 , "y Axis" , "ax.yaxis" )
144
143
145
144
# Spine
146
- circle (4.0 , 0.7 )
147
- text (4.0 , 0.7 - 0.2 , "Spine" )
145
+ circle (4.0 , 0.7 , "Spine" , "ax.spines" )
148
146
147
+ # frame around figure...
149
148
fig .add_artist (Rectangle ((0 , 0 ), width = 1 , height = 1 , facecolor = 'none' ,
150
149
edgecolor = '0.5' , linewidth = 10 ))
151
150
0 commit comments