Plotting and Animation

This module extends the pyplot module with functions to show scalar and vector fields in the usual simulation coordinate system (y-axis goes up), instead of the “image coordinate system” (y axis goes down) that matplotlib normally uses.

vector_field(array, step=2, **kwargs)

Plots given vector field as quiver (arrow) plot.

Parameters
  • array – numpy array with 3 dimensions, first two are spatial x,y coordinate, the last coordinate should have shape 2 and stores the 2 velocity components

  • step – plots only every steps’s cell, increase the step for high resolution arrays

  • kwargs – keyword arguments passed to matplotlib.pyplot.quiver()

Returns

quiver plot object

vector_field_magnitude(array, **kwargs)

Plots the magnitude of a vector field as colormap.

Parameters
  • array – numpy array with 3 dimensions, first two are spatial x,y coordinate, the last coordinate should have shape 2 and stores the 2 velocity components

  • kwargs – keyword arguments passed to matplotlib.pyplot.imshow()

Returns

imshow object

scalar_field(array, **kwargs)

Plots field values as colormap.

Works just as imshow, but uses coordinate system where second coordinate (y) points upwards.

Parameters
Returns

imshow object

scalar_field_surface(array, **kwargs)

Plots scalar field as 3D surface

Parameters
  • array – the two dimensional numpy array to plot

  • kwargs – keyword arguments passed to mpl_toolkits.mplot3d.Axes3D.plot_surface()

scalar_field_alpha_value(array, color, clip=False, **kwargs)

Plots an image with same color everywhere, using the array values as transparency.

Array is supposed to have values between 0 and 1 (if this is not the case it is normalized). An image is plotted that has the same color everywhere, the passed array determines the transparency. Regions where the array is 1 are fully opaque, areas with 0 are fully transparent.

Parameters
  • array – 2D array with alpha values

  • color – fill color

  • clip – if True, all values in the array larger than 1 are set to 1, all values smaller than 0 are set to zero if False, the array is linearly scaled to the [0, 1] interval

  • **kwargs – arguments passed to imshow

Returns

imshow object

scalar_field_contour(array, **kwargs)

Small wrapper around contour to transform the coordinate system.

For details see matplotlib.pyplot.imshow()

multiple_scalar_fields(array, **kwargs)

Plots a 3D array by slicing the last dimension and creates on plot for each entry of the last dimension.

Parameters
  • array – 3D array to plot.

  • **kwargs – passed along to imshow

phase_plot(phase_field, linewidth=1.0, clip=True)

Plots a phase field array using the phase variables as alpha channel.

Parameters
  • phase_field (ndarray) – array with len(shape) == 3, first two dimensions are spatial, the last one indexes the phase components.

  • linewidth – line width of the 0.5 contour lines that are drawn over the alpha blended phase images

  • clip – see scalar_field_alpha_value function

Return type

None

sympy_function(expr, x_values=None, **kwargs)

Plots the graph of a sympy term that depends on one symbol only.

Parameters
  • expr – sympy term that depends on one symbol only, which is plotted on the x axis

  • x_values – describes sampling of x axis. Possible values are: * tuple of (start, stop) or (start, stop, nr_of_steps) * None, then start=0, stop=1, nr_of_steps=100 * 1D numpy array with x values

  • **kwargs – passed on to matplotlib.pyplot.plot()

Returns

plot object

vector_field_animation(run_function, step=2, rescale=True, plot_setup_function=<function <lambda>>, plot_update_function=<function <lambda>>, interval=200, frames=180, **kwargs)

Creates a matplotlib animation of a vector field using a quiver plot.

Parameters
  • run_function – callable without arguments, returning a 2D vector field i.e. numpy array with len(shape)==3

  • step – see documentation of vector_field function

  • rescale – if True, the length of the arrows is rescaled in every time step

  • plot_setup_function – optional callable with the quiver object as argument, that can be used to set up the plot (title, legend,..)

  • plot_update_function – optional callable with the quiver object as argument that is called of the quiver object was updated

  • interval – delay between frames in milliseconds (see matplotlib.FuncAnimation)

  • frames – how many frames should be generated, see matplotlib.FuncAnimation

  • **kwargs – passed to quiver plot

Returns

matplotlib animation object

vector_field_magnitude_animation(run_function, plot_setup_function=<function <lambda>>, rescale=False, plot_update_function=<function <lambda>>, interval=30, frames=180, **kwargs)

Animation of a vector field, showing the magnitude as colormap.

For arguments, see vector_field_animation

scalar_field_animation(run_function, plot_setup_function=<function <lambda>>, rescale=True, plot_update_function=<function <lambda>>, interval=30, frames=180, **kwargs)

Animation of scalar field as colored image, see scalar_field.

surface_plot_animation(run_function, frames=90, interval=30, zlim=None, **kwargs)

Animation of scalar field as 3D plot.