Skip to content

Commit d779b5d

Browse files
committed
Update plotting in examples
1 parent 792ac28 commit d779b5d

File tree

8 files changed

+79
-57
lines changed

8 files changed

+79
-57
lines changed

examples/Envelope/danilov_envelope/benchmark_danilov_envelope_20.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from utils import make_fodo_lattice
2929
from utils import BunchMonitor
3030

31+
plt.style.use("style.mplstyle")
32+
3133

3234
# Parse arguments
3335
# --------------------------------------------------------------------------------------
@@ -123,31 +125,36 @@
123125
# Plot comparison
124126
# --------------------------------------------------------------------------------------
125127

126-
figwidth = 4.0 * args.periods
127-
figwidth = min(figwidth, 10.0)
128-
129-
fig, ax = plt.subplots(figsize=(figwidth, 2.5), constrained_layout=True)
130-
for i, key in enumerate(histories):
131-
history = histories[key]
132-
133-
plot_kws = {}
134-
if key == "envelope":
135-
plot_kws["ls"] = "-"
136-
plot_kws["lw"] = 2.5
137-
plot_kws["marker"] = None
138-
if key == "bunch":
139-
plot_kws["ls"] = "-"
140-
plot_kws["lw"] = 0.0
141-
plot_kws["marker"] = "."
142-
plot_kws["ms"] = 3.0
143-
plot_kws["color"] = "black"
144-
145-
ax.plot(history["s"], history["xrms"] * 1000.0, **plot_kws)
146-
ax.plot(history["s"], history["yrms"] * 1000.0, **plot_kws)
147-
148-
ax.set_ylim(0.0, ax.get_ylim()[1])
149-
ax.set_xlabel("Distance [m]")
150-
ax.set_ylabel("Size [mm]")
128+
figwidth = 3.0 * args.periods
129+
figwidth = min(figwidth, 7.0)
130+
131+
fig, axs = plt.subplots(nrows=2, figsize=(figwidth, 4.0), sharex=True, sharey=True)
132+
for i, ax in enumerate(axs):
133+
param = ["xrms", "yrms"][i]
134+
for j, key in enumerate(histories):
135+
history = histories[key]
136+
if key == "envelope":
137+
ax.plot(
138+
history["s"],
139+
np.multiply(history[param], 1000.0),
140+
color="black",
141+
lw=1.5,
142+
)
143+
else:
144+
stride = 10
145+
ax.plot(
146+
history["s"][::stride],
147+
np.multiply(history[param][::stride], 1000.0),
148+
marker=".",
149+
lw=0,
150+
color="red",
151+
)
152+
153+
for ax in axs:
154+
ax.set_ylim(0.0, ax.get_ylim()[1])
155+
axs[1].set_xlabel("Distance [m]")
156+
axs[0].set_ylabel("RMS x [mm]")
157+
axs[1].set_ylabel("RMS y [mm]")
151158

152159
filename = "fig_benchmark_rms.png"
153160
filename = os.path.join(output_dir, filename)

examples/Envelope/danilov_envelope/benchmark_danilov_envelope_22.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from utils import make_fodo_lattice
2929
from utils import BunchMonitor
3030

31+
plt.style.use("style.mplstyle")
32+
3133

3234
# Parse arguments
3335
# --------------------------------------------------------------------------------------
@@ -121,37 +123,38 @@
121123
# Plot comparison
122124
# --------------------------------------------------------------------------------------
123125

124-
figwidth = 4.0 * args.periods
125-
figwidth = min(figwidth, 6.0)
126-
127-
fig, axs = plt.subplots(figsize=(figwidth, 4.0), nrows=2, sharex=True, constrained_layout=True)
128-
for i, key in enumerate(histories):
129-
history = histories[key]
130-
131-
plot_kws = {}
132-
if key == "envelope":
133-
plot_kws["ls"] = "-"
134-
plot_kws["lw"] = 2.5
135-
plot_kws["marker"] = None
136-
if key == "bunch":
137-
plot_kws["ls"] = "-"
138-
plot_kws["lw"] = 0.0
139-
plot_kws["marker"] = "+"
140-
plot_kws["ms"] = 3.0
141-
plot_kws["color"] = "black"
142-
143-
axs[0].plot(history["s"], history["xrms"] * 1.00e03, **plot_kws)
144-
axs[0].plot(history["s"], history["yrms"] * 1.00e03, **plot_kws)
145-
axs[1].plot(history["s"], history["rxy"], **plot_kws)
146-
147-
axs[0].set_ylim(0.0, axs[0].get_ylim()[1])
148-
axs[1].set_ylim(-1.0, 1.0)
149-
150-
axs[0].set_xlabel("Distance [m]")
151-
axs[0].set_ylabel("Size [mm]")
152-
axs[1].set_ylabel("rxy")
153-
154-
filename = "fig_benchmark.png"
126+
figwidth = 3.0 * args.periods
127+
figwidth = min(figwidth, 7.0)
128+
129+
fig, axs = plt.subplots(nrows=2, figsize=(figwidth, 4.0), sharex=True, sharey=True)
130+
for i, ax in enumerate(axs):
131+
param = ["xrms", "yrms"][i]
132+
for j, key in enumerate(histories):
133+
history = histories[key]
134+
if key == "envelope":
135+
ax.plot(
136+
history["s"],
137+
np.multiply(history[param], 1000.0),
138+
color="black",
139+
lw=1.5,
140+
)
141+
else:
142+
stride = 10
143+
ax.plot(
144+
history["s"][::stride],
145+
np.multiply(history[param][::stride], 1000.0),
146+
marker=".",
147+
lw=0,
148+
color="red",
149+
)
150+
151+
for ax in axs:
152+
ax.set_ylim(0.0, ax.get_ylim()[1])
153+
axs[1].set_xlabel("Distance [m]")
154+
axs[0].set_ylabel("RMS x [mm]")
155+
axs[1].set_ylabel("RMS y [mm]")
156+
157+
filename = "fig_benchmark_rms.png"
155158
filename = os.path.join(output_dir, filename)
156159
plt.savefig(filename, dpi=300)
157160
plt.show()

examples/Envelope/danilov_envelope/match_danilov_envelope_20.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from utils import make_fodo_lattice
1818

19+
plt.style.use("style.mplstyle")
20+
1921

2022
# Parse arguments
2123
# --------------------------------------------------------------------------------------

examples/Envelope/danilov_envelope/match_danilov_envelope_22.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from utils import make_fodo_lattice
1818

19+
plt.style.use("style.mplstyle")
20+
1921

2022
# Parse arguments
2123
# --------------------------------------------------------------------------------------

examples/Envelope/danilov_envelope/plot_danilov_envelope_20.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from orbit.danilov_envelope import DanilovEnvelope20
55

6+
plt.style.use("style.mplstyle")
7+
68

79
envelope = DanilovEnvelope20(
810
eps_x=10.00e-06,

examples/Envelope/danilov_envelope/plot_danilov_envelope_22.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from orbit.danilov_envelope import DanilovEnvelope22
55

6+
plt.style.use("style.mplstyle")
7+
68

79
envelope = DanilovEnvelope22(
810
intrinsic_emittance=20.00e-06,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
axes.linewidth: 1.25
2+
figure.constrained_layout.use: True
3+
xtick.minor.visible: True
4+
ytick.minor.visible: True

examples/Envelope/danilov_envelope/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def make_fodo_lattice(
6161
fill_frac : Fraction of the lattice occupied by quadrupoles.
6262
start : str
6363
"drift":
64-
O-F-F-O-O-D-D-O.
64+
O-F-F-O-O-D-D-O.
6565
"quad":
6666
F-O-O-D-D-O-O-F
6767
fringe: Toggles fringe fields before/after quads.

0 commit comments

Comments
 (0)