6
6
This figure shows the name of several matplotlib elements composing a figure
7
7
"""
8
8
9
- import matplotlib .font_manager
10
- matplotlib .font_manager .findSystemFonts (fontpaths = None , fontext = 'ttf' )
11
9
12
10
import numpy as np
13
11
import matplotlib .pyplot as plt
12
+ from matplotlib .patches import Circle
13
+ from matplotlib .patheffects import withStroke
14
14
from matplotlib .ticker import AutoMinorLocator , MultipleLocator
15
15
16
16
royal_blue = "#002082"
17
17
royal_blue = [0 , 20 / 256 , 82 / 256 ]
18
18
19
+ # make the figure
20
+
19
21
np .random .seed (19680801 )
20
22
21
23
X = np .linspace (0.5 , 3.5 , 100 )
@@ -55,30 +57,30 @@ def minor_tick(x, pos):
55
57
marker = 'o' , markerfacecolor = 'none' , markeredgecolor = 'C4' , markeredgewidth = 2 )
56
58
57
59
ax .set_title ("Anatomy of a figure" , fontsize = 20 , verticalalignment = 'bottom' )
58
- ax .set_xlabel ("X axis label" , fontsize = 14 )
59
- ax .set_ylabel ("Y axis label" , fontsize = 14 )
60
+ ax .set_xlabel ("x Axis label" , fontsize = 14 )
61
+ ax .set_ylabel ("y Axis label" , fontsize = 14 )
60
62
61
63
ax .legend (loc = "upper right" , fontsize = 14 )
62
64
65
+ # Annotate the figure
63
66
64
67
def circle (x , y , radius = 0.15 ):
65
- from matplotlib .patches import Circle
66
- from matplotlib .patheffects import withStroke
67
- circle = Circle ((x , y ), radius , clip_on = False , zorder = 10 , linewidth = 2.5 ,
68
- edgecolor = royal_blue + [0.6 ], facecolor = (0 , 0 , 0 , .0 ),
69
- path_effects = [withStroke (linewidth = 7 , foreground = (1 , 1 , 1 , 1 ))])
70
- ax .add_artist (circle )
68
+ c = Circle ((x , y ), radius , clip_on = False , zorder = 10 , linewidth = 2.5 ,
69
+ edgecolor = royal_blue + [0.6 ], facecolor = 'none' ,
70
+ path_effects = [withStroke (linewidth = 7 , foreground = (1 , 1 , 1 , 1 ))])
71
+ ax .add_artist (c )
71
72
72
73
73
74
def text (x , y , text ):
74
- ax .text (x , y , text , backgroundcolor = ( 1 , 1 , 1 , 1 ), zorder = 100 ,
75
+ ax .text (x , y , text , zorder = 100 ,
75
76
ha = 'center' , va = 'top' , weight = 'bold' , color = royal_blue ,
76
- style = 'italic' , fontfamily = 'monospace' )
77
+ style = 'italic' , fontfamily = 'monospace' ,
78
+ path_effects = [withStroke (linewidth = 7 , foreground = (1 , 1 , 1 , 1 ))])
77
79
78
80
79
81
# Minor tick
80
- circle (0.50 , - 0.10 )
81
- text (0.50 , - 0.32 , "Minor tick label" )
82
+ circle (3.25 , - 0.10 )
83
+ text (3.25 , - 0.32 , "Minor tick label" )
82
84
83
85
# Major tick
84
86
circle (- 0.03 , 4.00 )
@@ -94,11 +96,11 @@ def text(x, y, text):
94
96
95
97
# X Label
96
98
circle (1.90 , - 0.27 )
97
- text (1.90 , - 0.47 , "X axis label " )
99
+ text (1.90 , - 0.47 , "xlabel " )
98
100
99
101
# Y Label
100
102
circle (- 0.27 , 1.75 )
101
- text (- 0.27 , 1.55 , "Y axis label " )
103
+ text (- 0.27 , 1.55 , "ylabel " )
102
104
103
105
# Title
104
106
circle (1.58 , 4.13 )
@@ -108,10 +110,6 @@ def text(x, y, text):
108
110
circle (1.75 , 2.80 )
109
111
text (1.75 , 2.60 , "Line\n (line plot)" )
110
112
111
- # Red plot
112
- #circle(1.20, 0.60)
113
- #text(1.20, 0.40, "Line\n(line plot)")
114
-
115
113
# Scatter plot
116
114
circle (2.25 , 1.54 )
117
115
text (2.25 , 1.34 , "Markers\n (scatter plot)" )
@@ -133,21 +131,17 @@ def text(x, y, text):
133
131
text (3.5 , 4.2 , "Figure" )
134
132
135
133
# Axis
136
- circle (2.7 , 0.01 )
137
- text (2.7 , - 0.2 , "x Axis" )
134
+ circle (0.65 , 0.01 )
135
+ text (0.65 , - 0.2 , "x Axis" )
138
136
139
137
# Axis
140
- circle (0 , 1.0 )
141
- text (0 , 1.0 - 0.2 , "y Axis" )
138
+ circle (0 , 0.7 )
139
+ text (0 , 0.7 - 0.2 , "y Axis" )
142
140
143
141
# Spine
144
142
circle (4.0 , 0.7 )
145
143
text (4.0 , 0.7 - 0.2 , "Spine" )
146
144
147
-
148
- #ax.text(4.0, -0.4, "Made with https://matplotlib.org",
149
- # fontsize=10, ha="right", color='.5')
150
-
151
145
plt .show ()
152
146
153
147
0 commit comments