22# Matplotlib cheat sheet
33# Released under the BSD License
44# -----------------------------------------------------------------------------
5+ import pathlib
56
67import numpy as np
8+ import matplotlib as mpl
79import matplotlib .pyplot as plt
810import matplotlib .patches as mpatches
911from matplotlib .collections import PatchCollection
1012
1113
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 )
1535
1636
1737box = mpatches .FancyBboxPatch (
1838 (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" )
2040ax .add_artist (box )
2141
2242box = mpatches .FancyBboxPatch (
2343 (0 , 0 ), 100 , 75 , mpatches .BoxStyle ("Round" , pad = 0 , rounding_size = 0 ),
24- linewidth = 1. , facecolor = "white" , edgecolor = "black" )
44+ facecolor = "white" , edgecolor = "black" )
2545ax .add_artist (box )
2646
2747
2848box = mpatches .Rectangle (
2949 (5 , 5 ), 45 , 30 , zorder = 10 ,
30- linewidth = 1.0 , facecolor = "white" , edgecolor = "black" )
50+ facecolor = "white" , edgecolor = "black" )
3151ax .add_artist (box )
3252
3353box = mpatches .Rectangle (
3454 (5 , 40 ), 45 , 30 , zorder = 10 ,
35- linewidth = 1.0 , facecolor = "white" , edgecolor = "black" )
55+ facecolor = "white" , edgecolor = "black" )
3656ax .add_artist (box )
3757
3858box = mpatches .Rectangle (
3959 (55 , 5 ), 40 , 65 , zorder = 10 ,
40- linewidth = 1.0 , facecolor = "white" , edgecolor = "black" )
60+ facecolor = "white" , edgecolor = "black" )
4161ax .add_artist (box )
4262
4363# Window button
4464X , 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" )
4767
4868
4969# Window size extension
5070X , 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 )
5272
5373X , 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 )
5575
5676X , 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 )
5878
5979X , 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 )
6181
6282
6383def ext_arrow (p0 , p1 , p2 , p3 ):
@@ -69,7 +89,7 @@ def ext_arrow(p0, p1, p2, p3):
6989 ax .arrow (* p3 , * (p2 - p3 ), zorder = 20 , linewidth = 0 ,
7090 length_includes_head = True , width = .4 ,
7191 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" )
7393
7494
7595def int_arrow (p0 , p1 ):
@@ -85,45 +105,44 @@ def int_arrow(p0, p1):
85105x = 0
86106y = 10
87107ext_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 )
89109
90110x += 50
91111ext_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 )
93113
94114x += 45
95115ext_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 )
97117
98118y = 0
99119x = 25
100120ext_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 )
102122
103123y += 35
104124ext_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 )
106126
107127y += 35
108128ext_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 )
110130
111131int_arrow ((0 , - 5 ), (100 , - 5 ))
112132ax .text (50 , - 5 , "figure width" , backgroundcolor = "white" , zorder = 30 ,
113- ha = "center" , va = "center" , size = "x-small" )
133+ ha = "center" , va = "center" )
114134
115135int_arrow ((105 , 0 ), (105 , 75 ))
116136ax .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" )
118138
119139int_arrow ((55 , 62.5 ), (95 , 62.5 ))
120140ax .text (75 , 62.5 , "axes width" , backgroundcolor = "white" , zorder = 30 ,
121- ha = "center" , va = "center" , size = "x-small" )
141+ ha = "center" , va = "center" )
122142
123143int_arrow ((62.5 , 5 ), (62.5 , 70 ))
124144ax .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" )
126146
127147
128148plt .savefig ("../figures/adjustments.pdf" )
129- # plt.show()
0 commit comments