-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadvanced_usage.py
62 lines (47 loc) · 1.77 KB
/
advanced_usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.axes import Axes
import pub_ready_plots as prp
########################################################################################
# User-specified rcParams override
########################################################################################
with prp.get_context(
layout=prp.Layout.ICLR,
width_frac=1,
height_frac=0.15,
override_rc_params={"lines.linewidth": 5}, # Pass your style overrides here!
) as (fig, ax):
assert isinstance(ax, Axes)
x = np.linspace(-1, 1, 100)
ax.plot(x, np.sin(x))
ax.set_title("Sine")
ax.set_xlabel(r"$x$")
ax.set_ylabel(r"$\mathrm{sin}(x)$")
fig.savefig("advanced_usage_1.pdf")
########################################################################################
# Manual, most-flexible way to use this library
########################################################################################
rc_params, fig_width_in, fig_height_in = prp.get_mpl_rcParams(
layout=prp.Layout.POSTER_PORTRAIT,
width_frac=1,
height_frac=0.15,
single_col=False,
)
# You can update `rc_params` further before feeding it to `plt`, e.g.
rc_params.update({"axes.linewidth": 1})
# Use the styles globally.
# To make it local, use `with plt.rc_context(rc_params):`
plt.rcParams.update(rc_params)
fig, axs = plt.subplots(1, 2, constrained_layout=True)
fig.set_size_inches(fig_width_in, fig_height_in)
x = np.linspace(-1, 1, 100)
assert isinstance(axs, np.ndarray)
axs[0].plot(x, np.sin(x))
axs[0].set_title("Sine")
axs[0].set_xlabel(r"$x$")
axs[0].set_ylabel(r"$\mathrm{sin}(x)$")
axs[1].plot(x, np.cos(x))
axs[1].set_title("Cosine")
axs[1].set_xlabel(r"$x$")
axs[1].set_ylabel(r"$\mathrm{cos}(x)$")
fig.savefig("advanced_usage_2.pdf")