magpylib.graphics package#
Additional plotting features
- class magpylib.graphics.Trace3d(backend='generic', constructor=None, args=None, kwargs=None, coordsargs=None, show=True, scale=1, updatefunc=None, **params)#
Bases:
MagicPropertiesUser-defined 3D model trace that moves/rotates with its parent object.
Use this to attach custom geometry to an object for display. Traces are positioned relative to the object and transformed together with it; they can also replace the default 3D representation if desired.
- Parameters:
backend ({'generic', 'matplotlib', 'plotly'}, default 'generic') – Plotting backend for this trace.
constructor (str | None, default None) – Name of the constructor function/method to build the 3D model (e.g.,
'plot_trisurf','Mesh3d'). Must match the selected backend.args (tuple | callable | None, default None) – Positional arguments for the constructor, or a callable returning them.
kwargs (dict | callable | None, default None) – Keyword arguments for the constructor, or a callable returning them.
coordsargs (dict | None, default None) – Names of coordinate arrays to be transformed; by default
{"x": "x", "y": "y", "z": "z"}. IfFalse, the object is not rotated.show (bool, default True) – Show or hide the resulting model3d object.
scale (float, default 1) – Multiplier applied to the trace vertex coordinates.
updatefunc (callable | None, default None) – Callable with no arguments returning a dictionary of trace parameters to update at show time. Enables dynamic, attribute-dependent trace updates.
- as_dict(flatten=False, separator='.')#
Returns recursively a nested dictionary with all properties objects of the class
- Parameters:
flatten (bool) – If
True, the nested dictionary gets flatten out with provided separator for the dictionary keysseparator (str) – the separator to be used when flattening the dictionary. Only applies if
flatten=True
- copy()#
returns a copy of the current class instance
- update(arg=None, _match_properties=True, _replace_None_only=False, **kwargs)#
Updates the class properties with provided arguments, supports magic underscore notation
- Parameters:
_match_properties (bool) – If
True, checks if provided properties over keyword arguments are matching the current object properties. An error is raised if a non-matching property is found. IfFalse, theupdatemethod does not raise any error when an argument is not matching a property._replace_None_only – updates matching properties that are equal to
None(not already been set)
- Return type:
self
- property args#
Positional arguments for the constructor (
tupleor callable).
- property backend#
Plotting backend for this trace. One of {‘generic’, ‘matplotlib’, ‘plotly’}.
- property constructor#
Constructor name to build the 3D model (e.g.,
'plot_trisurf','Mesh3d'). Must match the selected backend.
- property coordsargs#
Names of coordinate arrays to transform; default
{"x":"x", "y":"y", "z":"z"}. IfFalse, the object is not rotated.
- property kwargs#
Keyword arguments for the constructor (
dictor callable).
- property scale#
Multiplier applied to the trace vertex coordinates.
- property show#
Show or hide the model3d trace.
- property updatefunc#
Callable object with no arguments. Should return a dictionary with keys from the trace parameters. If provided, the function is called at show time and updates the trace parameters with the output dictionary. This allows to update a trace dynamically depending on class attributes, and postpone the trace construction to when the object is displayed.