2
2
# Matplotlib cheat sheet
3
3
# Released under the BSD License
4
4
# -----------------------------------------------------------------------------
5
+ import pathlib
5
6
6
7
import numpy as np
8
+ import matplotlib as mpl
7
9
import matplotlib .pyplot as plt
8
10
import matplotlib .patches as mpatches
9
11
from matplotlib .collections import PatchCollection
10
12
11
13
12
- fig = plt .figure (figsize = (4.25 , 4.25 * 95 / 115 ))
13
- ax = fig .add_axes ([0 , 0 , 1 , 1 ], frameon = False , aspect = 1 ,
14
- xlim = (0 - 5 , 100 + 10 ), ylim = (- 10 , 80 + 5 ), xticks = [], yticks = [])
14
+ mpl .style .use ([
15
+ pathlib .Path (__file__ ).parent / '../styles/base.mplstyle' ,
16
+ ])
17
+ mpl .rc ('font' , size = 4 )
18
+ mpl .rc ('lines' , linewidth = 0.5 )
19
+ mpl .rc ('patch' , linewidth = 0.5 )
20
+
21
+
22
+ subplots_kw = dict (
23
+ figsize = (5.7 / 2.54 , 5.7 / 2.54 * 95 / 115 ),
24
+ subplot_kw = dict (
25
+ frameon = False ,
26
+ aspect = 1 ,
27
+ xlim = (0 - 5 , 100 + 10 ),
28
+ ylim = (- 10 , 80 + 5 ),
29
+ xticks = [],
30
+ yticks = [],
31
+ ),
32
+ )
33
+
34
+ (fig , ax ) = plt .subplots (** subplots_kw )
15
35
16
36
17
37
box = mpatches .FancyBboxPatch (
18
38
(0 , 0 ), 100 , 83 , mpatches .BoxStyle ("Round" , pad = 0 , rounding_size = 2 ),
19
- linewidth = 1. , facecolor = "0.9" , edgecolor = "black" )
39
+ facecolor = "0.9" , edgecolor = "black" )
20
40
ax .add_artist (box )
21
41
22
42
box = mpatches .FancyBboxPatch (
23
43
(0 , 0 ), 100 , 75 , mpatches .BoxStyle ("Round" , pad = 0 , rounding_size = 0 ),
24
- linewidth = 1. , facecolor = "white" , edgecolor = "black" )
44
+ facecolor = "white" , edgecolor = "black" )
25
45
ax .add_artist (box )
26
46
27
47
28
48
box = mpatches .Rectangle (
29
49
(5 , 5 ), 45 , 30 , zorder = 10 ,
30
- linewidth = 1.0 , facecolor = "white" , edgecolor = "black" )
50
+ facecolor = "white" , edgecolor = "black" )
31
51
ax .add_artist (box )
32
52
33
53
box = mpatches .Rectangle (
34
54
(5 , 40 ), 45 , 30 , zorder = 10 ,
35
- linewidth = 1.0 , facecolor = "white" , edgecolor = "black" )
55
+ facecolor = "white" , edgecolor = "black" )
36
56
ax .add_artist (box )
37
57
38
58
box = mpatches .Rectangle (
39
59
(55 , 5 ), 40 , 65 , zorder = 10 ,
40
- linewidth = 1.0 , facecolor = "white" , edgecolor = "black" )
60
+ facecolor = "white" , edgecolor = "black" )
41
61
ax .add_artist (box )
42
62
43
63
# Window button
44
64
X , Y = [5 , 10 , 15 ], [79 , 79 , 79 ]
45
- plt .scatter (X , Y , s = 75 , zorder = 10 ,
46
- edgecolor = "black" , facecolor = "white" , linewidth = 1 )
65
+ plt .scatter (X , Y , s = 20 , zorder = 10 ,
66
+ edgecolor = "black" , facecolor = "white" )
47
67
48
68
49
69
# Window size extension
50
70
X , Y = [0 , 0 ], [0 , - 8 ]
51
- plt .plot (X , Y , color = "black" , linestyle = ":" , linewidth = 1 , clip_on = False )
71
+ plt .plot (X , Y , color = "black" , linestyle = ":" , clip_on = False )
52
72
53
73
X , Y = [100 , 100 ], [0 , - 8 ]
54
- plt .plot (X , Y , color = "black" , linestyle = ":" , linewidth = 1 , clip_on = False )
74
+ plt .plot (X , Y , color = "black" , linestyle = ":" , clip_on = False )
55
75
56
76
X , Y = [100 , 108 ], [0 , 0 ]
57
- plt .plot (X , Y , color = "black" , linestyle = ":" , linewidth = 1 , clip_on = False )
77
+ plt .plot (X , Y , color = "black" , linestyle = ":" , clip_on = False )
58
78
59
79
X , Y = [100 , 108 ], [75 , 75 ]
60
- plt .plot (X , Y , color = "black" , linestyle = ":" , linewidth = 1 , clip_on = False )
80
+ plt .plot (X , Y , color = "black" , linestyle = ":" , clip_on = False )
61
81
62
82
63
83
def ext_arrow (p0 , p1 , p2 , p3 ):
@@ -69,7 +89,7 @@ def ext_arrow(p0, p1, p2, p3):
69
89
ax .arrow (* p3 , * (p2 - p3 ), zorder = 20 , linewidth = 0 ,
70
90
length_includes_head = True , width = .4 ,
71
91
head_width = 2 , head_length = 2 , color = "black" )
72
- plt .plot ([p1 [0 ], p2 [0 ]], [p1 [1 ], p2 [1 ]], linewidth = .9 , color = "black" )
92
+ plt .plot ([p1 [0 ], p2 [0 ]], [p1 [1 ], p2 [1 ]], linewidth = .5 , color = "black" )
73
93
74
94
75
95
def int_arrow (p0 , p1 ):
@@ -85,45 +105,44 @@ def int_arrow(p0, p1):
85
105
x = 0
86
106
y = 10
87
107
ext_arrow ( (x - 4 , y ), (x , y ), (x + 5 , y ), (x + 9 , y ) )
88
- ax .text (x + 9.5 , y , "left" , ha = "left" , va = "center" , size = "x-small" , zorder = 20 )
108
+ ax .text (x + 9.5 , y , "left" , ha = "left" , va = "center" , zorder = 20 )
89
109
90
110
x += 50
91
111
ext_arrow ( (x - 4 , y ), (x , y ), (x + 5 , y ), (x + 9 , y ) )
92
- ax .text (x - 4.5 , y , "wspace" , ha = "right" , va = "center" , size = "x-small" , zorder = 20 )
112
+ ax .text (x - 4.5 , y , "wspace" , ha = "right" , va = "center" , zorder = 20 )
93
113
94
114
x += 45
95
115
ext_arrow ( (x - 4 , y ), (x , y ), (x + 5 , y ), (x + 9 , y ) )
96
- ax .text (x - 4.5 , y , "right" , ha = "right" , va = "center" , size = "x-small" , zorder = 20 )
116
+ ax .text (x - 4.5 , y , "right" , ha = "right" , va = "center" , zorder = 20 )
97
117
98
118
y = 0
99
119
x = 25
100
120
ext_arrow ( (x , y - 4 ), (x , y ), (x , y + 5 ), (x , y + 9 ) )
101
- ax .text (x , y + 9.5 , "bottom" , ha = "center" , va = "bottom" , size = "x-small" , zorder = 20 )
121
+ ax .text (x , y + 9.5 , "bottom" , ha = "center" , va = "bottom" , zorder = 20 )
102
122
103
123
y += 35
104
124
ext_arrow ( (x , y - 4 ), (x , y ), (x , y + 5 ), (x , y + 9 ) )
105
- ax .text (x , y - 4.5 , "hspace" , ha = "center" , va = "top" , size = "x-small" , zorder = 20 )
125
+ ax .text (x , y - 4.5 , "hspace" , ha = "center" , va = "top" , zorder = 20 )
106
126
107
127
y += 35
108
128
ext_arrow ( (x , y - 4 ), (x , y ), (x , y + 5 ), (x , y + 9 ) )
109
- ax .text (x , y - 4.5 , "top" , ha = "center" , va = "top" , size = "x-small" , zorder = 20 )
129
+ ax .text (x , y - 4.5 , "top" , ha = "center" , va = "top" , zorder = 20 )
110
130
111
131
int_arrow ((0 , - 5 ), (100 , - 5 ))
112
132
ax .text (50 , - 5 , "figure width" , backgroundcolor = "white" , zorder = 30 ,
113
- ha = "center" , va = "center" , size = "x-small" )
133
+ ha = "center" , va = "center" )
114
134
115
135
int_arrow ((105 , 0 ), (105 , 75 ))
116
136
ax .text (105 , 75 / 2 , "figure height" , backgroundcolor = "white" , zorder = 30 ,
117
- rotation = "vertical" , ha = "center" , va = "center" , size = "x-small" )
137
+ rotation = "vertical" , ha = "center" , va = "center" )
118
138
119
139
int_arrow ((55 , 62.5 ), (95 , 62.5 ))
120
140
ax .text (75 , 62.5 , "axes width" , backgroundcolor = "white" , zorder = 30 ,
121
- ha = "center" , va = "center" , size = "x-small" )
141
+ ha = "center" , va = "center" )
122
142
123
143
int_arrow ((62.5 , 5 ), (62.5 , 70 ))
124
144
ax .text (62.5 , 35 , "axes height" , backgroundcolor = "white" , zorder = 30 ,
125
- rotation = "vertical" , ha = "center" , va = "center" , size = "x-small" )
145
+ rotation = "vertical" , ha = "center" , va = "center" )
126
146
127
147
128
148
plt .savefig ("../figures/adjustments.pdf" )
129
- # plt.show()
0 commit comments