Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1537f9d
ENH/REF: split up plotting + add Bokeh particle plot
ken-lauer Feb 20, 2026
bc27744
ENH: basic marginal plot font settings
ken-lauer Mar 17, 2026
b0b3a12
ENH: a bit more font customization options
ken-lauer Mar 18, 2026
2fd8df0
ENH: stats mouseover
ken-lauer Apr 18, 2026
a7a4e18
FIX: scale_both for the joint figure
ken-lauer Apr 23, 2026
cdf3280
REF: migrate all plots to support different backends
ken-lauer Apr 24, 2026
2455100
STY/MAINT: py310+
ken-lauer Apr 24, 2026
908c72a
MAINT: unused **kwargs (ew) for protocol compat
ken-lauer Apr 24, 2026
e368911
FIX: support log scale in bokeh marginals
ken-lauer Apr 24, 2026
8dfe246
FIX: Limits + more protocol stuff
ken-lauer Apr 24, 2026
b739b7a
MAINT: test artifacts should not be version controlled
ken-lauer Apr 24, 2026
45b3281
FIX: min bins + colorbar is title not label
ken-lauer Apr 24, 2026
c6aeaeb
TST: bokeh plot initial testing
ken-lauer Apr 24, 2026
e2b7e00
BLD: optional bokeh dep
ken-lauer Apr 24, 2026
44f4c87
ENH: bokeh jupyter handling from pytao
ken-lauer Apr 24, 2026
bd89b59
Merge remote-tracking branch 'origin/master' into enh_bokeh_rebase
ken-lauer Apr 24, 2026
7cdb661
ENH: density_and_slice_plot with bokeh as well
ken-lauer Apr 24, 2026
f3bcd76
FIX: consistent return_figure handling
ken-lauer Apr 24, 2026
864e710
FIX: mathjax labels
ken-lauer Apr 24, 2026
a0ff982
WIP: alternate spot for stats - bottom
ken-lauer Apr 24, 2026
80e3b3f
MAINT: maybe throw away kwargs for now :/
ken-lauer Apr 24, 2026
1f445cd
DOC: add plot backend comparison
ken-lauer Apr 24, 2026
aa37321
DOC: actually use 'set_default_backend'
ken-lauer Apr 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ venv.bak/
.DS_Store

/beamphysics/_version.py

/tests/artifacts
4 changes: 4 additions & 0 deletions beamphysics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"Wavefront": ".wavefront",
"WavefrontK": ".wavefront",
"pmd_init": ".writers",
"set_default_backend": ".plot_dispatch",
"get_default_backend": ".plot_dispatch",
}


Expand All @@ -35,6 +37,8 @@
"particle_paths",
"pmd_init",
"single_particle",
"set_default_backend",
"get_default_backend",
"Wavefront",
"WavefrontK",
]
Expand Down
61 changes: 35 additions & 26 deletions beamphysics/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .interfaces.lucretia import write_lucretia
from .interfaces.opal import write_opal
from .interfaces.simion import write_simion
from .plot import density_plot, marginal_plot, slice_plot, wakefield_plot
from .plot_dispatch import get_backend
from .readers import particle_array, particle_paths
from .species import charge_of, mass_of
from .statistics import (
Expand Down Expand Up @@ -1381,6 +1381,7 @@ def plot(
tex=True,
nice=True,
ellipse=False,
backend=None,
**kwargs,
):
"""
Expand All @@ -1397,7 +1398,7 @@ def plot(

Parameters
----------
key1 : str, default = 't'
key1 : str, default = 'x'
Key to bin on the x-axis

key2 : str, default = None
Expand All @@ -1423,25 +1424,28 @@ def plot(
2x2 sigma matrix

return_figure : bool, default = False
If true, return a matplotlib.figure.Figure object
If true, return the figure/layout object

**kwargs
Any additional kwargs to send to the the plot in: plt.subplots(**kwargs)
backend : str, optional
Plot backend: ``'mpl'`` or ``'bokeh'``.
Defaults to the module-level setting (see ``set_default_backend``).

**kwargs
Additional keyword arguments passed to the backend plot function.

Returns
-------
None or fig: matplotlib.figure.Figure
This only returns a figure object if return_figure=T, otherwise returns None

None or figure object
Returns the figure only if ``return_figure=True``.
"""
be = get_backend(backend)

if not key2:
fig = density_plot(
fig = be.density_plot(
self, key=key1, bins=bins, xlim=xlim, tex=tex, nice=nice, **kwargs
)
else:
fig = marginal_plot(
fig = be.marginal_plot(
self,
key1=key1,
key2=key2,
Expand Down Expand Up @@ -1514,6 +1518,7 @@ def slice_plot(
return_figure=False,
xlim=None,
ylim=None,
backend=None,
**kwargs,
):
"""
Expand All @@ -1533,20 +1538,23 @@ def slice_plot(
nice : bool, optional
Scale to nice units. Default is True.
return_figure : bool, optional
If True, return the matplotlib Figure. Default is False.
If True, return the figure/layout object. Default is False.
xlim : tuple of float, optional
Manual x-axis limits in raw units.
ylim : tuple of float, optional
Manual y-axis limits in raw units.
backend : str, optional
Plot backend: ``'mpl'`` or ``'bokeh'``.
**kwargs
Additional keyword arguments passed to ``plt.subplots``.
Additional keyword arguments passed to the backend plot function.

Returns
-------
None or matplotlib.figure.Figure
Returns a Figure only if ``return_figure=True``.
None or figure object
Returns the figure only if ``return_figure=True``.
"""
fig = slice_plot(
be = get_backend(backend)
fig = be.slice_plot(
self,
*keys,
n_slice=n_slice,
Expand Down Expand Up @@ -1619,11 +1627,11 @@ def wakefield_plot(
wake: WakefieldBase,
key=None,
nice=True,
ax=None,
xlim=None,
ylim=None,
tex=True,
bins=None,
backend=None,
**kwargs,
):
"""
Expand All @@ -1647,9 +1655,6 @@ def wakefield_plot(
nice : bool, default=True
If True, applies unit-aware scaling using SI prefixes (e.g., mm, ns).

ax : matplotlib.axes.Axes, optional
An existing Axes to plot into. If None, a new figure and axes are created.

xlim : tuple of float, optional
Limits to apply to the x-axis, in native units.

Expand All @@ -1662,21 +1667,25 @@ def wakefield_plot(
bins : int or str, optional
Number of bins to use for the density histogram.

kwargs : dict
Additional keyword arguments passed to `plt.subplots()` if a new axis is created.
backend : str, optional
Plot backend: ``'mpl'`` or ``'bokeh'``.

ax : matplotlib.axes.Axes, optional
Matplotlib-only: An existing Axes to plot into. (part of **kwargs)

**kwargs
Additional keyword arguments passed to the backend plot function.

Returns
-------
fig : matplotlib.figure.Figure
The matplotlib figure containing the plot.
figure object
"""

wakefield_plot(
be = get_backend(backend)
return be.wakefield_plot(
self,
wake,
key=key,
nice=nice,
ax=ax,
xlim=xlim,
ylim=ylim,
tex=tex,
Expand Down
Loading
Loading