Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b59d61

Browse files
committed
Use context for switching styles
1 parent 60cb4c4 commit 7b59d61

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

scripts/styles.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
import matplotlib as mpl
77
import matplotlib.pyplot as plt
88

9-
styles = ['default'] + plt.style.available
10-
11-
for style in styles:
12-
fig = plt.figure(figsize=(5,3), dpi=100)
13-
plt.style.use(style)
14-
ax = plt.subplot(1,1,1)
15-
X = np.linspace(0,2*np.pi, 256)
16-
Y = np.cos(X)
17-
ax.plot(X,Y)
18-
plt.title(style, family="Source Serif Pro", size=32)
19-
plt.tight_layout()
20-
# plt.show()
21-
plt.savefig("../figures/style-%s.pdf" % style)
22-
plt.close(fig)
9+
for style in ['default'] + plt.style.available:
10+
with plt.style.context(style):
11+
fig = plt.figure(figsize=(5,3), dpi=100)
12+
ax = plt.subplot(1,1,1)
13+
X = np.linspace(0,2*np.pi, 256)
14+
Y = np.cos(X)
15+
ax.plot(X,Y)
16+
plt.title(style, family="Source Serif Pro", size=32)
17+
plt.tight_layout()
18+
plt.savefig("../figures/style-%s.pdf" % style)
19+
plt.close(fig)
2320

2421

0 commit comments

Comments
 (0)