#!/usr/bin/env python # coding: utf-8 # # 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: # In[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: # In[2]: mesh.slider("x") # 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. # In[3]: mesh.slider("x", description="my slider") # Similar to plots, we can change the multiplier: # In[4]: mesh.slider("x", multiplier=1e-12) # We now get the values in picometers and the units are shown in the widget description. # # Slider is based on [ipywidgets.SelectionSlider](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#SelectionSlider), so any keyword arguments accepted by it can be passed. # In[5]: mesh.slider("x", orientation="vertical") # ## Axis selector # # A simple widget, which allows us to select the axis we want can be obtained as: # In[6]: mesh.axis_selector() # 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'`. # In[7]: mesh.axis_selector(widget="radiobuttons") # The description of the widget, similar to slider, can be changed using `description` string. # In[8]: mesh.axis_selector(description="my selector")