4
4
import matplotlib .pyplot as plt
5
5
import scienceplots
6
6
7
+ import os
8
+
9
+ # Check we are in examples dir
10
+ current_dir = os .getcwd ().lower ()
11
+ if (current_dir .endswith ('scienceplots' )):
12
+ os .chdir ('./examples' )
13
+ # Create 'figures' folder if it does not exist
14
+ if (not os .path .exists ('./figures' )):
15
+ os .makedirs ('figures' )
16
+
7
17
def model (x , p ):
8
18
return x ** (2 * p + 1 ) / (1 + x ** (2 * p ))
9
19
@@ -19,8 +29,8 @@ def model(x, p):
19
29
ax .legend (title = 'Order' )
20
30
ax .autoscale (tight = True )
21
31
ax .set (** pparam )
22
- fig .savefig ('figures/fig1.pdf' )
23
- fig . savefig ( 'figures/fig1.jpg' , dpi = 300 )
32
+ fig .savefig ('figures/fig01.jpg' , dpi = 300 )
33
+ plt . close ( )
24
34
25
35
with plt .style .context (['science' , 'ieee' ]):
26
36
fig , ax = plt .subplots ()
@@ -29,10 +39,8 @@ def model(x, p):
29
39
ax .legend (title = 'Order' )
30
40
ax .autoscale (tight = True )
31
41
ax .set (** pparam )
32
- # Note: $\mu$ doesn't work with Times font (used by ieee style)
33
- ax .set_ylabel (r'Current (\textmu A)' )
34
- fig .savefig ('figures/fig2a.pdf' )
35
- fig .savefig ('figures/fig2a.jpg' , dpi = 300 )
42
+ fig .savefig ('figures/fig02a.jpg' , dpi = 300 )
43
+ plt .close ()
36
44
37
45
with plt .style .context (['science' , 'ieee' , 'std-colors' ]):
38
46
fig , ax = plt .subplots ()
@@ -41,10 +49,8 @@ def model(x, p):
41
49
ax .legend (title = 'Order' )
42
50
ax .autoscale (tight = True )
43
51
ax .set (** pparam )
44
- # Note: $\mu$ doesn't work with Times font (used by ieee style)
45
- ax .set_ylabel (r'Current (\textmu A)' )
46
- fig .savefig ('figures/fig2b.pdf' )
47
- fig .savefig ('figures/fig2b.jpg' , dpi = 300 )
52
+ fig .savefig ('figures/fig02b.jpg' , dpi = 300 )
53
+ plt .close ()
48
54
49
55
with plt .style .context (['science' , 'nature' ]):
50
56
fig , ax = plt .subplots ()
@@ -53,8 +59,8 @@ def model(x, p):
53
59
ax .legend (title = 'Order' )
54
60
ax .autoscale (tight = True )
55
61
ax .set (** pparam )
56
- fig .savefig ('figures/fig2c.pdf' )
57
- fig . savefig ( 'figures/fig2c.jpg' , dpi = 300 )
62
+ fig .savefig ('figures/fig02c.jpg' , dpi = 300 )
63
+ plt . close ( )
58
64
59
65
with plt .style .context (['science' , 'scatter' ]):
60
66
fig , ax = plt .subplots (figsize = (4 , 4 ))
@@ -73,8 +79,8 @@ def model(x, p):
73
79
ax .set_ylabel (ylbl )
74
80
ax .set_xlim ([- 2 , 2 ])
75
81
ax .set_ylim ([- 2 , 2 ])
76
- fig .savefig ('figures/fig3.pdf' )
77
- fig . savefig ( 'figures/fig3.jpg' , dpi = 300 )
82
+ fig .savefig ('figures/fig03.jpg' , dpi = 300 )
83
+ plt . close ( )
78
84
79
85
with plt .style .context (['science' , 'high-vis' ]):
80
86
fig , ax = plt .subplots ()
@@ -83,8 +89,8 @@ def model(x, p):
83
89
ax .legend (title = 'Order' )
84
90
ax .autoscale (tight = True )
85
91
ax .set (** pparam )
86
- fig .savefig ('figures/fig4.pdf' )
87
- fig . savefig ( 'figures/fig4.jpg' , dpi = 300 )
92
+ fig .savefig ('figures/fig04.jpg' , dpi = 300 )
93
+ plt . close ( )
88
94
89
95
with plt .style .context (['dark_background' , 'science' , 'high-vis' ]):
90
96
fig , ax = plt .subplots ()
@@ -93,8 +99,8 @@ def model(x, p):
93
99
ax .legend (title = 'Order' )
94
100
ax .autoscale (tight = True )
95
101
ax .set (** pparam )
96
- fig .savefig ('figures/fig5.pdf' )
97
- fig . savefig ( 'figures/fig5.jpg' , dpi = 300 )
102
+ fig .savefig ('figures/fig05.jpg' , dpi = 300 )
103
+ plt . close ( )
98
104
99
105
with plt .style .context (['science' , 'notebook' ]):
100
106
fig , ax = plt .subplots ()
@@ -103,8 +109,8 @@ def model(x, p):
103
109
ax .legend (title = 'Order' )
104
110
ax .autoscale (tight = True )
105
111
ax .set (** pparam )
106
- fig .savefig ('figures/fig10.pdf' )
107
112
fig .savefig ('figures/fig10.jpg' , dpi = 300 )
113
+ plt .close ()
108
114
109
115
# Plot different color cycles
110
116
@@ -115,8 +121,8 @@ def model(x, p):
115
121
ax .legend (title = 'Order' )
116
122
ax .autoscale (tight = True )
117
123
ax .set (** pparam )
118
- fig .savefig ('figures/fig6.pdf' )
119
- fig . savefig ( 'figures/fig6.jpg' , dpi = 300 )
124
+ fig .savefig ('figures/fig06.jpg' , dpi = 300 )
125
+ plt . close ( )
120
126
121
127
with plt .style .context (['science' , 'vibrant' ]):
122
128
fig , ax = plt .subplots ()
@@ -125,8 +131,8 @@ def model(x, p):
125
131
ax .legend (title = 'Order' )
126
132
ax .autoscale (tight = True )
127
133
ax .set (** pparam )
128
- fig .savefig ('figures/fig7.pdf' )
129
- fig . savefig ( 'figures/fig7.jpg' , dpi = 300 )
134
+ fig .savefig ('figures/fig07.jpg' , dpi = 300 )
135
+ plt . close ( )
130
136
131
137
with plt .style .context (['science' , 'muted' ]):
132
138
fig , ax = plt .subplots ()
@@ -135,8 +141,8 @@ def model(x, p):
135
141
ax .legend (title = 'Order' , fontsize = 7 )
136
142
ax .autoscale (tight = True )
137
143
ax .set (** pparam )
138
- fig .savefig ('figures/fig8.pdf' )
139
- fig . savefig ( 'figures/fig8.jpg' , dpi = 300 )
144
+ fig .savefig ('figures/fig08.jpg' , dpi = 300 )
145
+ plt . close ( )
140
146
141
147
with plt .style .context (['science' , 'retro' ]):
142
148
fig , ax = plt .subplots ()
@@ -145,8 +151,8 @@ def model(x, p):
145
151
ax .legend (title = 'Order' )
146
152
ax .autoscale (tight = True )
147
153
ax .set (** pparam )
148
- fig .savefig ('figures/fig9.pdf' )
149
- fig . savefig ( 'figures/fig9.jpg' , dpi = 300 )
154
+ fig .savefig ('figures/fig09.jpg' , dpi = 300 )
155
+ plt . close ( )
150
156
151
157
with plt .style .context (['science' , 'grid' ]):
152
158
fig , ax = plt .subplots ()
@@ -155,8 +161,8 @@ def model(x, p):
155
161
ax .legend (title = 'Order' )
156
162
ax .autoscale (tight = True )
157
163
ax .set (** pparam )
158
- fig .savefig ('figures/fig11.pdf' )
159
164
fig .savefig ('figures/fig11.jpg' , dpi = 300 )
165
+ plt .close ()
160
166
161
167
with plt .style .context (['science' , 'high-contrast' ]):
162
168
fig , ax = plt .subplots ()
@@ -165,8 +171,8 @@ def model(x, p):
165
171
ax .legend (title = 'Order' )
166
172
ax .autoscale (tight = True )
167
173
ax .set (** pparam )
168
- fig .savefig ('figures/fig12.pdf' )
169
174
fig .savefig ('figures/fig12.jpg' , dpi = 300 )
175
+ plt .close ()
170
176
171
177
with plt .style .context (['science' , 'light' ]):
172
178
fig , ax = plt .subplots ()
@@ -175,8 +181,8 @@ def model(x, p):
175
181
ax .legend (title = 'Order' , fontsize = 7 )
176
182
ax .autoscale (tight = True )
177
183
ax .set (** pparam )
178
- fig .savefig ('figures/fig13.pdf' )
179
184
fig .savefig ('figures/fig13.jpg' , dpi = 300 )
185
+ plt .close ()
180
186
181
187
# Note: You need to install the Noto Serif CJK Fonts before running
182
188
# examples 14 and 15. See FAQ in README.
@@ -190,6 +196,7 @@ def model(x, p):
190
196
ax .set (ylabel = r'電流 ($\mu$A)' )
191
197
ax .autoscale (tight = True )
192
198
fig .savefig ('figures/fig14a.jpg' , dpi = 300 )
199
+ plt .close ()
193
200
194
201
with plt .style .context (['science' , 'no-latex' , 'cjk-sc-font' ]):
195
202
fig , ax = plt .subplots ()
@@ -200,6 +207,7 @@ def model(x, p):
200
207
ax .set (ylabel = r'电流 ($\mu$A)' )
201
208
ax .autoscale (tight = True )
202
209
fig .savefig ('figures/fig14b.jpg' , dpi = 300 )
210
+ plt .close ()
203
211
204
212
with plt .style .context (['science' , 'no-latex' , 'cjk-jp-font' ]):
205
213
fig , ax = plt .subplots ()
@@ -210,6 +218,7 @@ def model(x, p):
210
218
ax .set (ylabel = r'電気 ($\mu$A)' )
211
219
ax .autoscale (tight = True )
212
220
fig .savefig ('figures/fig14c.jpg' , dpi = 300 )
221
+ plt .close ()
213
222
214
223
with plt .style .context (['science' , 'no-latex' , 'cjk-kr-font' ]):
215
224
fig , ax = plt .subplots ()
@@ -220,6 +229,7 @@ def model(x, p):
220
229
ax .set (ylabel = r'전류 ($\mu$A)' )
221
230
ax .autoscale (tight = True )
222
231
fig .savefig ('figures/fig14d.jpg' , dpi = 300 )
232
+ plt .close ()
223
233
224
234
# import matplotlib
225
235
# matplotlib.use('pgf') # stwich backend to pgf
@@ -243,6 +253,7 @@ def model(x, p):
243
253
# ax.set(ylabel=r'電流 ($\mu$A)')
244
254
# ax.autoscale(tight=True)
245
255
# fig.savefig('figures/fig15.pdf', backend='pgf')
256
+ # plt.close()
246
257
247
258
with plt .style .context (['science' , 'russian-font' ]):
248
259
fig , ax = plt .subplots ()
@@ -253,6 +264,7 @@ def model(x, p):
253
264
ax .set (ylabel = r'Сила тока ($\mu$A)' )
254
265
ax .autoscale (tight = True )
255
266
fig .savefig ('figures/fig16.jpg' , dpi = 300 )
267
+ plt .close ()
256
268
257
269
with plt .style .context (['science' , 'turkish-font' ]):
258
270
fig , ax = plt .subplots ()
@@ -263,3 +275,4 @@ def model(x, p):
263
275
ax .set (ylabel = r'Mevcut Güç/Akım ($\mu$A)' )
264
276
ax .autoscale (tight = True )
265
277
fig .savefig ('figures/fig17.jpg' , dpi = 300 )
278
+ plt .close ()
0 commit comments