github magpylib/magpylib 1.1.0-beta
magpylib v1.1.0-beta

latest releases: 5.0.1, 5.0.0, 5.0.0rc0...
4 years ago

magpylib v1.1.0-beta Release Notes

Hello! This beta version releases a fix and a new displaySystem feature, alongside documentation updates.

New Feature

For Collections, implemented one new kwarg for displaySystem():

  • subplotAx=None
    • This is subplot figure data that already exists. displaySystem will take this and plot the 3D inside of it. It needs to be 3D projected.

This allows for creating side-by-side plots using displaySystem.

Figure information must be set manually in pyplot.figure() in order to not squash the plots upon subplotting.

Code Example
import numpy as np
import matplotlib.pyplot as plt
from magpylib.source.magnet import Box
from magpylib import Collection

#create collection of four magnets
s1 = Box(mag=[ 500,0, 500], dim=[3,3,3], pos=[ 0,0, 3], angle=45, axis=[0,1,0])
s2 = Box(mag=[-500,0,-500], dim=[3,3,3], pos=[ 0,0,-3], angle=45, axis=[0,1,0])
s3 = Box(mag=[ 500,0,-500], dim=[4,4,4], pos=[ 4,0, 0], angle=45, axis=[0,1,0])
s4 = Box(mag=[-500,0, 500], dim=[4,4,4], pos=[-4,0, 0], angle=45, axis=[0,1,0])
c = Collection(s1,s2,s3,s4)

#create positions
xs = np.linspace(-8,8,100)
zs = np.linspace(-6,6,100)
posis = [[x,0,z] for z in zs for x in xs]

#calculate fields
Bs = c.getBsweep(posis)

#reshape array and calculate amplitude
Bs = np.array(Bs).reshape([100,100,3])
Bamp = np.linalg.norm(Bs,axis=2)

##amplitude plot
X,Z = np.meshgrid(xs,zs)

##Define Figure
fig = plt.figure()

##Define ax for 2D
ax1 = fig.add_subplot(1, 2, 1, axisbelow=True)
##Define ax for 3D displaySystem
ax2 = fig.add_subplot(1, 2, 2, axisbelow=True,projection='3d')




##field plot 2D
ax1.contourf(X,Z,Bamp,100,cmap='rainbow')
U,V = Bs[:,:,0], Bs[:,:,2]
ax1.streamplot(X, Z, U, V, color='k', density=2)

##plot 3D ax with Collection's displaySystem 
c.displaySystem(subplotAx=ax2)

Output:
image

Fixes and Tweaks

  • getBsweep() for Collections and Sources now always returns a numpy array
  • Zero-length segments in Line sources now return [0,0,0] and a warning, making it easier to draw spirals.
  • Added a workaround fix for a rotation bug we are still working on.

Don't miss a new magpylib release

NewReleases is sending notifications on new releases.