Graphics - Styles#

The graphic styles define how Magpylib objects are displayed visually when calling show. They can be fine-tuned and individualized in many ways.

There are multiple hierarchy levels that decide about the final graphical representation of the objects:

  1. When no input is given, the default style will be applied.

  2. Collections will override the color property of all children with their own color.

  3. Object individual styles will take precedence over these values.

  4. Setting a local style in show() will take precedence over all other settings.

Setting the default style#

The default style is stored in Default styles can be set as properties, = True = 'grey' = 'bicolor'

by assigning a style dictionary with equivalent keys, = {
    'magnetization': {'show': True, 'color': {'middle': 'grey', 'mode': 'tricolor'}}

or by making use of the update method:
    'show': True,
    'color': {'middle'='grey', mode='tricolor',}

All three examples result in the same default style.

Once modified, the library default can always be restored with the method. The following practical example demonstrates how to create and set a user defined magnetization style as default,

import magpylib as magpy
from magpylib.magnet import Cuboid, Cylinder, Sphere

cube = Cuboid(magnetization=(1, 0, 0), dimension=(1, 1, 1))
cylinder = Cylinder(magnetization=(0, 1, 0), dimension=(1, 1), position=(2,0,0))
sphere = Sphere(magnetization=(0, 1, 1), diameter=1, position=(4,0,0))

print('Default magnetization style'), cylinder, sphere, backend="plotly")

user_defined_style = {
    'show': True,
    'color': {
        'transition': 1,
        'mode': 'tricolor',
        'middle': 'white',
        'north': 'magenta',
        'south': 'turquoise',
} = user_defined_style

print('Custom magnetization style'), cylinder, sphere, backend="plotly")
Default magnetization style