Mesh widgets#
In order to control interactive plots, sometimes we need to vary certain parameters which depend on the mesh. Therefore, mesh object has several widgets, which can be used for that purpose.
The mesh we are going to use as an example is:
[1]:
import discretisedfield as df
p1 = (0, 0, 0)
p2 = (100e-9, 50e-9, 20e-9)
n = (20, 10, 4)
region = df.Region(p1=p1, p2=p2)
mesh = df.Mesh(region=region, n=n)
Slider#
Slider widget allows us to navigate through the coordinates of the mesh along the certain axis. For instance, if we want to “slide through” the x-axis, the widget is:
[2]:
mesh.slider("x")
[2]:
The minimum value of the slider is the x-coordinate of the cell with the minimum coordinates, whereas the maximum value is the x-coordinate of the last cell along the x-direction. The steps on the slider correspond to the distance between cells.
Widget description is generated by default, and can be changed by passing description
argument.
[3]:
mesh.slider("x", description="my slider")
[3]:
Similar to plots, we can change the multiplier:
[4]:
mesh.slider("x", multiplier=1e-12)
[4]:
We now get the values in picometers and the units are shown in the widget description.
Slider is based on ipywidgets.SelectionSlider, so any keyword arguments accepted by it can be passed.
[5]:
mesh.slider("x", orientation="vertical")
[5]:
Axis selector#
A simple widget, which allows us to select the axis we want can be obtained as:
[6]:
mesh.axis_selector()
[6]:
By default, a dropdown menu is returned where we can select x, y, or z axis. Instead of a dropdown menu, we can ask for radio buttons, by passing widget='radiobuttons'
.
[7]:
mesh.axis_selector(widget="radiobuttons")
[7]:
The description of the widget, similar to slider, can be changed using description
string.
[8]:
mesh.axis_selector(description="my selector")
[8]: