magpylib.graphics package#

The magpylib.display sub-package provides additional plotting features for independent use.

class magpylib.graphics.Trace3d(backend=None, constructor=None, args=None, kwargs=None, coordsargs=None, show=True, scale=1, updatefunc=None, **params)#

Bases: magpylib._src.defaults.defaults_utility.MagicProperties

Defines properties for an additional user-defined 3d model object which is positioned relatively to the main object to be displayed and moved automatically with it. This feature also allows the user to replace the original 3d representation of the object.

Parameters
  • backend (str) – Plotting backend corresponding to the trace. Can be one of [‘matplotlib’, ‘plotly’].

  • constructor (str) – Model constructor function or method to be called to build a 3D-model object (e.g. ‘plot_trisurf’, ‘Mesh3d). Must be in accordance with the given plotting backend.

  • args (tuple, default=None) – Tuple or callable returning a tuple containing positional arguments for building a 3D-model object.

  • kwargs (dict or callable, default=None) – Dictionary or callable returning a dictionary containing the keys/values pairs for building a 3D-model object.

  • coordsargs (dict, default=None) –

    Tells magpylib the name of the coordinate arrays to be moved or rotated,

    by default: {“x”: “x”, “y”: “y”, “z”: “z”}, if False, object is not rotated.

  • show (bool, default=True) – Shows/hides model3d object based on provided trace.

  • scale (float, default=1) – Scaling factor by which the trace vertices coordinates are multiplied.

  • updatefunc (callable, default=None) – 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.

property args#

Tuple or callable returning a tuple containing positional arguments for building a 3D-model object.

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 keys

  • separator (str) – the separator to be used when flattening the dictionary. Only applies if flatten=True

property backend#

Plotting backend corresponding to the trace. Can be one of [‘matplotlib’, ‘plotly’].

property constructor#

Model constructor function or method to be called to build a 3D-model object (e.g. ‘plot_trisurf’, ‘Mesh3d). Must be in accordance with the given plotting backend.

property coordsargs#

Tells magpylib the name of the coordinate arrays to be moved or rotated, by default: {“x”: “x”, “y”: “y”, “z”: “z”}, if False, object is not rotated.

copy()#

returns a copy of the current class instance

property kwargs#

Dictionary or callable returning a dictionary containing the keys/values pairs for building a 3D-model object.

property scale#

Scaling factor by which the trace vertices coordinates are multiplied.

property show#

If True, show default model3d object representation, else hide it.

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. If False, the update method 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 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.

Subpackages#