magpylib.graphics package#

Additional plotting features

class magpylib.graphics.Trace3d(**kwargs)#

Bases: PropertyNode

User-defined 3D model trace that moves/rotates with its parent object.

Parameters:
  • backend (str, default 'generic') – Plotting backend for this trace: ‘generic’, any of the built-in backends in magpylib.SUPPORTED_PLOTTING_BACKENDS, or a backend registered at runtime.

  • 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"}.

  • 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.

as_dict(flatten=False, separator='.')#

Return all effective values as a nested dict (flatten=True for a flat dict with separator-joined keys).

copy()#

Return a detached, unobserved deep copy.

get(path)#

Return the value at a dotted path, e.g. 'arrow.width'.

is_set(name)#

Return whether a direct property holds an explicitly set value (for child nodes: whether anything in the subtree is set).

merged(*layers)#

Return a copy where unset properties are filled from the given layers, first-set-wins (self has the highest priority).

observe(callback)#

Register callback(path, value) to fire on any change in this subtree; path is the dotted path of the changed property relative to this node.

classmethod schema()#

Return the JSON-Schema description of the field tree.

set(path, value)#

Set the value at a dotted path and return self.

set_values(separator='.')#

Return a flat {dotted_path: value} dict of all explicitly set leaf values.

unobserve(callback)#

Unregister a previously registered callback.

update(arg=None, _match_properties=True, _replace_None_only=False, **kwargs)#

Update properties from a dict and/or keyword arguments, supporting magic underscore notation. Nested dicts merge into child nodes.

Parameters:
  • _match_properties (bool) – If True (default), unknown property names raise an AttributeError; if False they are silently ignored.

  • _replace_None_only (bool) – If True, only properties that are not explicitly set get updated.

args#

A tuple, or a callable returning one.

backend#

A field restricted to a set of allowed values.

The values are given either directly, or as a single zero-argument callable returning them, for sets that are only known at call time (e.g. the display backends registered so far). A callable is re-evaluated on every validate() and schema(), so a generated schema describes the choices as they stand at generation time.

constructor#

A string field, optionally coercing any input via str().

coordsargs#

A dict with ‘x’, ‘y’, ‘z’ keys naming coordinate arrays.

kwargs#

A dict, or a callable returning one.

scale#

A float or int field with optional bounds.

show#

A strict True/False field.

updatefunc#

A callable with no arguments returning a dict of Trace3d parameters.

Subpackages#