default module
Define a default plotter.
- class DefaultPlotter(vedo_backend='2d', *args, **kwargs)[source]
Bases:
PlotterAn object using maptlotlib for 2D, Vedo for 3D.
- Parameters:
vedo_backend (
Literal['k3d','vtk','2d'], default:'2d')
- __init__(vedo_backend='2d', *args, **kwargs)[source]
Set basic settings for the 3D Vedo plotter.
- Parameters:
vedo_backend (
Literal['k3d','vtk','2d'], default:'2d') –The backend used by
vedo. The options that I tested were:"k3d": Needs additional libraries (pip install -e .[k3d]). A little bugged, see_k3d_patch()."vtk": Interactive 3D plots."2d": Non-interactive 2D plots.
- property vedo_backend: Literal['k3d', 'vtk', '2d']
The name of the vedo backend; a priori, no need to access that.
- plot(data, x, y, grid=True, axes=None, xlabel=None, ylabel=None, label=None, **kwargs)[source]
Plot 2D data.
- Parameters:
data (
DataFrame) – Holds all data to plot.x (
str) – Name of column indatafor x/y.y (
str) – Name of column indatafor x/y.grid (
bool, default:True) – If grid should be plotted. Default is True.axes (
Axes|None, default:None) – Axes to re-use, if provided. The default is None (plot on new axis).xlabel (
str|None, default:None) – Name of the labels. If not provided, we use the markdown equivalent of x/y, if defined inmarkdown.ylabel (
str|None, default:None) – Name of the labels. If not provided, we use the markdown equivalent of x/y, if defined inmarkdown.label (
str|None, default:None) – If provided, overrides the legend. Useful when several simulations are shown on the same plot.kwargs – Other keyword passed to the
pd.DataFrame.plotmethod.
- Return type:
tuple[Axes|ndarray[tuple[Any,...],dtype[Any]],tuple[float,float,float] |str|tuple[float,float,float,float] |tuple[tuple[float,float,float] |str,float] |tuple[tuple[float,float,float,float],float]]- Returns:
axes (Axes | NDArray[Any]) – Objects created by the
pd.DataFrame.plotmethod.color (ColorType) – Color used for the plot.
- hist(data, x, bins=200, hist_range=None, xlabel=None, title=None, **kwargs)[source]
Plot a histogram.
- Parameters:
data (pandas.DataFrame) – Holds all data to plot.
x (PARTICLE_0D_t) – Name of the column in
datato plot.bins (int, optional) – Number of bins in the histogram. The default is 200.
hist_range (tuple[float, float] | None, optional) – Lower and upper range for the calculation of the histogram. The default is None.
kwargs – Other keyword arguments passed to the actual plot method.
- Returns:
Axis object.
- Return type:
Any
- plot_3d(data, key, *args, **kwargs)[source]
Create a 3D plot.
- Parameters:
data (Any) – Object storing the data to plot.
key (PARTICLE_3D_t) – Name/nature of the data to plot.
- Return type:
- plot_mesh(mesh, *args, **kwargs)[source]
Plot the mesh (
STLfile).- Parameters:
mesh (
Mesh)- Return type:
Plotter
- plot_trajectory(points, emission_color=None, collision_color=None, collision_point=array([], dtype=float64), lw=7, r=2, **kwargs)[source]
Plot the
Particletrajectory stored inpoints.- Parameters:
points (
list[ndarray[tuple[Any,...],dtype[float64]]]) – List of positions, as returned byVector.to_list().emission_color (
str|None, default:None) – If provided, the first known position is colored with this color.collision_color (
str|None, default:None) – If provided, the last known position is colored with this color.collision_point (
ndarray[tuple[Any,...],dtype[float64]], default:array([], dtype=float64)) – If provided andcollision_coloris notNone, we plot this point instead of the last ofpoints. This is useful when the extrapolated time is large, and actuel collision point may differ significantly from last position points.lw (
int, default:7) – Trajectory line width.r (
int, default:2) – Size of the emission/collision points.
- Return type:
Plotter
- _k3d_patch()[source]
Patch
point_sizeto avoid following error.File "/home/placais/Documents/simulation/python/simultipac/examples/./analyze_cst_particle_monitor.py", line 61, in <module> result.show() ~~~~~~~~~~~^^ File "/home/placais/Documents/simulation/python/simultipac/src/simultipac/simulation_results/simulation_results.py", line 324, in show return self._plotter.show() ~~~~~~~~~~~~~~~~~~^^ File "/home/placais/Documents/simulation/python/simultipac/src/simultipac/plotter/default.py", line 235, in show _plotter_3d.show() ~~~~~~~~~~~~~~~~^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/vedo/plotter.py", line 3337, in show return backends.get_notebook_backend(self.objects) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/vedo/backends.py", line 31, in get_notebook_backend return start_k3d(actors2show) File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/vedo/backends.py", line 349, in start_k3d kobj = k3d.points( ia.coordinates.astype(np.float32), ...<5 lines>... name=name, ) File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/k3d/factory.py", line 620, in points Points( ~~~~~~^ positions=positions, ^^^^^^^^^^^^^^^^^^^^ ...<15 lines>... compression_level=compression_level, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ), ^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/k3d/objects.py", line 735, in __init__ super(Points, self).__init__(**kwargs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/k3d/objects.py", line 194, in __init__ super(DrawableWithCallback, self).__init__(**kwargs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/k3d/objects.py", line 108, in __init__ super(Drawable, self).__init__(**kwargs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/ipywidgets/widgets/widget.py", line 478, in __init__ super(Widget, self).__init__(**kwargs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/traitlets/traitlets.py", line 1355, in __init__ setattr(self, key, value) ~~~~~~~^^^^^^^^^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/traitlets/traitlets.py", line 716, in __set__ self.set(obj, value) ~~~~~~~~^^^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/traitlets/traitlets.py", line 690, in set new_value = self._validate(obj, value) File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/traitlets/traitlets.py", line 722, in _validate value = self.validate(obj, value) File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/traitlets/traitlets.py", line 2460, in validate self.error(obj, value) ~~~~~~~~~~^^^^^^^^^^^^ File "/home/placais/.pyenv/versions/simultipac/lib/python3.13/site-packages/traitlets/traitlets.py", line 831, in error raise TraitError(e) traitlets.traitlets.TraitError: The 'point_size' trait of a Points instance expected a float or a dict, not the float64 np.float64(0.0).
This method overrides the default
k3d.objects.Pointsconstructor. May be related to this issue. This quick patch seems to raise other errors… So for now, prefer"vtk".- Return type: