Display backends

Display backendsΒΆ

The magpylib package is shipped with a display function which provides a graphical representation of every magnet, current and sensor of the library. To date the library includes two possible backends:

  • matplotlib (by default)

  • plotly

Display multiple objects, object paths, markers in 3D using Matplotlib:

import magpylib as magpy
magnet = magpy.magnet.Cuboid(magnetization=(1, 0, 0), dimension=(1, 2, 3))
sens = magpy.Sensor(position=(0, 0, 3))
magpy.display(magnet, sens, zoom=1)
../../_images/plot_02_display_backends_3_0.png

Display figure on your own canvas (here Matplotlib 3D axis):

import matplotlib.pyplot as plt
import magpylib as magpy

my_axis = plt.axes(projection="3d")
src = magpy.magnet.Sphere(magnetization=(0, 0, 1), diameter=1)
src.move([(0.1, 0, 0)] * 50, increment=True)
src.rotate_from_angax(angle=[10] * 50, axis="z", anchor=0, start=0, increment=True)
ts = [-0.4, 0, 0.4]
sens = magpy.Sensor(position=(0, 0, 2), pixel=[(x, y, 0) for x in ts for y in ts])
magpy.display(src, sens, canvas=my_axis)
plt.show()
../../_images/plot_02_display_backends_5_0.png

The same objects can also be displayed using the plotly plotting backend

import magpylib as magpy

src = magpy.magnet.Sphere(magnetization=(0, 0, 1), diameter=1)
src.move([(0.1, 0, 0)] * 50, increment=True)
src.rotate_from_angax(angle=[10] * 50, axis="z", anchor=0, start=0, increment=True)
ts = [-0.4, 0, 0.4]
sens = magpy.Sensor(position=(0, 0, 2), pixel=[(x, y, 0) for x in ts for y in ts])
magpy.display(src, backend="plotly")