Skip to content

Commit

Permalink
Fix matplotlib errors
Browse files Browse the repository at this point in the history
  • Loading branch information
proy30 committed Dec 17, 2024
1 parent 9e4987e commit de94727
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/python/impactx/dashboard/Analyze/plotsMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def load_dataTable_data():
state.filtered_data = []
state.all_data = []
state.all_headers = []
state.phase_space_png = None

# -----------------------------------------------------------------------------
# Functions to update table/plot
Expand Down Expand Up @@ -134,14 +135,13 @@ def update_plot():
state.show_table = True
elif state.active_plot == "Phase Space Plots":
state.show_table = False
ctrl.matplotlib_figure_update(state.simulation_data)


def run_simulation_impactX():
buf = io.StringIO()

with pipes(stdout=buf, stderr=buf):
state.simulation_data = run_simulation()
run_simulation()

buf.seek(0)
lines = [line.strip() for line in buf.getvalue().splitlines()]
Expand Down Expand Up @@ -232,7 +232,9 @@ def plot():
vuetify.VDivider()
with vuetify.VTabsItems(v_model="active_tab"):
with vuetify.VTabItem():
vuetify.VImg(v_if=("image_data",), src=("image_data",))
vuetify.VImg(
v_if=("phase_space_png",), src=("phase_space_png",)
)

with vuetify.VTabItem():
with vuetify.VContainer(
Expand Down
4 changes: 3 additions & 1 deletion src/python/impactx/dashboard/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ def run_simulation():
sim.evolve()

fig = adjusted_settings_plot(pc)
ctrl.matplotlib_figure_update(fig)

fig_original = pc.plot_phasespace()

if fig_original is not None:
image_base64 = fig_to_base64(fig_original)
state.image_data = f"data:image/png;base64, {image_base64}"
state.phase_space_png = f"data:image/png;base64, {image_base64}"

sim.finalize()

Expand Down

0 comments on commit de94727

Please sign in to comment.