flatspin.plotting#

flatspin.plotting.quadrilaterals(X)#
flatspin.plotting.format_label(label, format_spec='{:g}')#
flatspin.plotting.format_labels(labels, format_spec='{:g}')#
flatspin.plotting.heatmap2(X, Y, Z, xlabel='x', ylabel='y', zlabel='z', xlabels=None, ylabels=None, **kwargs)#
flatspin.plotting.heatmap(X, Y, Z, xlabel='x', ylabel='y', zlabel='z', xlim=None, ylim=None, zlim=None, nticks=10, xlabel_format='{:g}', ylabel_format='{:g}', ax=None, **kwargs)#
flatspin.plotting.vector_angle(U, V)#
flatspin.plotting.vector_rgba(U, V, mag_max=1, cmap='hsv')#

Return rgba values according to color map and normalized vector magnitude.

flatspin.plotting.mask_zero_vectors(UV)#
class flatspin.plotting.SpinQuiver(*args, style='arrow', **kwargs)#

Custom Quiver with support for different spin styles (shapes)

The constructor takes one required argument, an Axes instance, followed by the args and kwargs described by the following pyplot interface documentation:

Plot a 2D field of arrows.

Call signature:

quiver([X, Y], U, V, [C], **kwargs)

X, Y define the arrow locations, U, V define the arrow directions, and C optionally sets the color.

Arrow length

The default settings auto-scales the length of the arrows to a reasonable size. To change this behavior see the scale and scale_units parameters.

Arrow shape

The arrow shape is determined by width, headwidth, headlength and headaxislength. See the notes below.

Arrow styling

Each arrow is internally represented by a filled polygon with a default edge linewidth of 0. As a result, an arrow is rather a filled area, not a line with a head, and .PolyCollection properties like linewidth, edgecolor, facecolor, etc. act accordingly.

Parameters:
  • X (1D or 2D array-like, optional) –

    The x and y coordinates of the arrow locations.

    If not given, they will be generated as a uniform integer meshgrid based on the dimensions of U and V.

    If X and Y are 1D but U, V are 2D, X, Y are expanded to 2D using X, Y = np.meshgrid(X, Y). In this case len(X) and len(Y) must match the column and row dimensions of U and V.

  • Y (1D or 2D array-like, optional) –

    The x and y coordinates of the arrow locations.

    If not given, they will be generated as a uniform integer meshgrid based on the dimensions of U and V.

    If X and Y are 1D but U, V are 2D, X, Y are expanded to 2D using X, Y = np.meshgrid(X, Y). In this case len(X) and len(Y) must match the column and row dimensions of U and V.

  • U (1D or 2D array-like) –

    The x and y direction components of the arrow vectors. The interpretation of these components (in data or in screen space) depends on angles.

    U and V must have the same number of elements, matching the number of arrow locations in X, Y. U and V may be masked. Locations masked in any of U, V, and C will not be drawn.

  • V (1D or 2D array-like) –

    The x and y direction components of the arrow vectors. The interpretation of these components (in data or in screen space) depends on angles.

    U and V must have the same number of elements, matching the number of arrow locations in X, Y. U and V may be masked. Locations masked in any of U, V, and C will not be drawn.

  • C (1D or 2D array-like, optional) –

    Numeric data that defines the arrow colors by colormapping via norm and cmap.

    This does not support explicit colors. If you want to set colors directly, use color instead. The size of C must match the number of arrow locations.

  • angles ({'uv', 'xy'} or array-like, default: 'uv') –

    Method for determining the angle of the arrows.

    • ’uv’: Arrow direction in screen coordinates. Use this if the arrows symbolize a quantity that is not based on X, Y data coordinates.

      If U == V the orientation of the arrow on the plot is 45 degrees counter-clockwise from the horizontal axis (positive to the right).

    • ’xy’: Arrow direction in data coordinates, i.e. the arrows point from (x, y) to (x+u, y+v). Use this e.g. for plotting a gradient field.

    • Arbitrary angles may be specified explicitly as an array of values in degrees, counter-clockwise from the horizontal axis.

      In this case U, V is only used to determine the length of the arrows.

    Note: inverting a data axis will correspondingly invert the arrows only with angles='xy'.

  • pivot ({'tail', 'mid', 'middle', 'tip'}, default: 'tail') –

    The part of the arrow that is anchored to the X, Y grid. The arrow rotates about this point.

    ’mid’ is a synonym for ‘middle’.

  • scale (float, optional) –

    Scales the length of the arrow inversely.

    Number of data units per arrow length unit, e.g., m/s per plot width; a smaller scale parameter makes the arrow longer. Default is None.

    If None, a simple autoscaling algorithm is used, based on the average vector length and the number of vectors. The arrow length unit is given by the scale_units parameter.

  • scale_units ({'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, optional) –

    If the scale kwarg is None, the arrow length unit. Default is None.

    e.g. scale_units is ‘inches’, scale is 2.0, and (u, v) = (1, 0), then the vector will be 0.5 inches long.

    If scale_units is ‘width’ or ‘height’, then the vector will be half the width/height of the axes.

    If scale_units is ‘x’ then the vector will be 0.5 x-axis units. To plot vectors in the x-y plane, with u and v having the same units as x and y, use angles='xy', scale_units='xy', scale=1.

  • units ({'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width') –

    Affects the arrow size (except for the length). In particular, the shaft width is measured in multiples of this unit.

    Supported values are:

    • ’width’, ‘height’: The width or height of the Axes.

    • ’dots’, ‘inches’: Pixels or inches based on the figure dpi.

    • ’x’, ‘y’, ‘xy’: X, Y or \(\sqrt{X^2 + Y^2}\) in data units.

    The following table summarizes how these values affect the visible arrow size under zooming and figure size changes:

    units

    zoom

    figure size change

    ’x’, ‘y’, ‘xy’

    arrow size scales

    ‘width’, ‘height’

    arrow size scales

    ’dots’, ‘inches’

  • width (float, optional) –

    Shaft width in arrow units. All head parameters are relative to width.

    The default depends on choice of units above, and number of vectors; a typical starting value is about 0.005 times the width of the plot.

  • headwidth (float, default: 3) – Head width as multiple of shaft width. See the notes below.

  • headlength (float, default: 5) – Head length as multiple of shaft width. See the notes below.

  • headaxislength (float, default: 4.5) – Head length at shaft intersection as multiple of shaft width. See the notes below.

  • minshaft (float, default: 1) – Length below which arrow scales, in units of head length. Do not set this to less than 1, or small arrows will look terrible!

  • minlength (float, default: 1) – Minimum length as a multiple of shaft width; if an arrow length is less than this, plot a dot (hexagon) of this diameter instead.

  • color (:mpltype:`color` or list :mpltype:`color`, optional) –

    Explicit color(s) for the arrows. If C has been set, color has no effect.

    This is a synonym for the .PolyCollection facecolor parameter.

  • data (indexable object, optional) – DATA_PARAMETER_PLACEHOLDER

  • **kwargs (~matplotlib.collections.PolyCollection properties, optional) –

    All other keyword arguments are passed on to .PolyCollection:

    Properties: agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: array-like or scalar or None animated: bool antialiased or aa or antialiaseds: bool or list of bools array: array-like or None capstyle: .CapStyle or {‘butt’, ‘projecting’, ‘round’} clim: (vmin: float, vmax: float) clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None cmap: .Colormap or str or None color: :mpltype:`color` or list of RGBA tuples edgecolor or ec or edgecolors: :mpltype:`color` or list of :mpltype:`color` or ‘face’ facecolor or facecolors or fc: :mpltype:`color` or list of :mpltype:`color` figure: ~matplotlib.figure.Figure gid: str hatch: {‘/’, ‘\’, ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’} in_layout: bool joinstyle: .JoinStyle or {‘miter’, ‘round’, ‘bevel’} label: object linestyle or dashes or linestyles or ls: str or tuple or list thereof linewidth or linewidths or lw: float or list of floats mouseover: bool norm: .Normalize or str or None offset_transform or transOffset: .Transform offsets: (N, 2) or (2,) array-like path_effects: list of .AbstractPathEffect paths: list of array-like picker: None or bool or float or callable pickradius: float rasterized: bool sizes: numpy.ndarray or None sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: ~matplotlib.transforms.Transform url: str urls: list of str or None verts: list of array-like verts_and_codes: unknown visible: bool zorder: float

Return type:

~matplotlib.quiver.Quiver

See also

Axes.quiverkey

Add a key to a quiver plot.

Notes

Arrow shape

The arrow is drawn as a polygon using the nodes as shown below. The values headwidth, headlength, and headaxislength are in units of width.

_static/quiver_sizes.svg

The defaults give a slightly swept-back arrow. Here are some guidelines how to get other head shapes:

  • To make the head a triangle, make headaxislength the same as headlength.

  • To make the arrow more pointed, reduce headwidth or increase headlength and headaxislength.

  • To make the head smaller relative to the shaft, scale down all the head parameters proportionally.

  • To remove the head completely, set all head parameters to 0.

  • To get a diamond-shaped head, make headaxislength larger than headlength.

  • Warning: For headaxislength < (headlength / headwidth), the “headaxis” nodes (i.e. the ones connecting the head with the shaft) will protrude out of the head in forward direction so that the arrow head looks broken.

set_verts(verts, closed=True)#

Set the vertices of the polygons.

Parameters:
  • verts (list of array-like) – The sequence of polygons [verts0, verts1, …] where each element verts_i defines the vertices of polygon i as a 2D array-like of shape (M, 2).

  • closed (bool, default: True) – Whether the polygon should be closed by adding a CLOSEPOLY connection at the end.

set(*, UVC=<UNSET>, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, array=<UNSET>, capstyle=<UNSET>, clim=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, cmap=<UNSET>, color=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, gid=<UNSET>, hatch=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, norm=<UNSET>, offset_transform=<UNSET>, offsets=<UNSET>, path_effects=<UNSET>, paths=<UNSET>, picker=<UNSET>, pickradius=<UNSET>, rasterized=<UNSET>, sizes=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, urls=<UNSET>, verts=<UNSET>, verts_and_codes=<UNSET>, visible=<UNSET>, zorder=<UNSET>)#

Set multiple properties at once.

Supported properties are

Properties:

UVC: unknown agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: array-like or scalar or None animated: bool antialiased or aa or antialiaseds: bool or list of bools array: array-like or None capstyle: .CapStyle or {‘butt’, ‘projecting’, ‘round’} clim: (vmin: float, vmax: float) clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None cmap: .Colormap or str or None color: :mpltype:`color` or list of RGBA tuples edgecolor or ec or edgecolors: :mpltype:`color` or list of :mpltype:`color` or ‘face’ facecolor or facecolors or fc: :mpltype:`color` or list of :mpltype:`color` figure: ~matplotlib.figure.Figure gid: str hatch: {‘/’, ‘\’, ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’} in_layout: bool joinstyle: .JoinStyle or {‘miter’, ‘round’, ‘bevel’} label: object linestyle or dashes or linestyles or ls: str or tuple or list thereof linewidth or linewidths or lw: float or list of floats mouseover: bool norm: .Normalize or str or None offset_transform or transOffset: .Transform offsets: (N, 2) or (2,) array-like path_effects: list of .AbstractPathEffect paths: list of array-like picker: None or bool or float or callable pickradius: float rasterized: bool sizes: numpy.ndarray or None sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: ~matplotlib.transforms.Transform url: str urls: list of str or None verts: unknown verts_and_codes: unknown visible: bool zorder: float

flatspin.plotting.spin_quiver(*args, ax=None, **kwargs)#
flatspin.plotting.plot_vectors(XY, UV, C=None, style='arrow', mask_zero=True, replace=False, normalize=False, ax=None, set_ax_lims=True, dir_only=False, alpha_mag=False, **kwargs)#
flatspin.plotting.get_voronoi_polys(XY, bounding_hull=None)#
flatspin.plotting.plot_voronoi(XY, UV, bounding_hull=None, alpha=1.0, arrows=False, mask_zero=True, edgecolor='none', replace=False, ax=None, **kwargs)#
flatspin.plotting.plot_vector_image(XY, UV, mask_zero=True, replace=False, cmap='flatspin', ax=None)#
flatspin.plotting.montage_fig(n_axes, title=False)#

Create a figure with n_axes subplots on a grid

flatspin.plotting.vector_montage(axes, positions, vectors, labels=None, style='image', **kwargs)#
flatspin.plotting.save_animation(ani, outfile, fps=30, dpi=100)#
class flatspin.plotting.FuncAnimationCtrl(fig, func, frames, **kwargs)#

FuncAnimation with key controls to control playback

frame_iter()#
pause()#

Pause the animation.

resume()#

Resume the animation.

new_frame_seq()#

Return a new sequence of frame information.

step()#
on_press(event)#
flatspin.plotting.plot_h_ext(h_ext)#
flatspin.plotting.gridless_crop(x, crop_percent)#

Return the indices of x that are inside the crop

flatspin.plotting.plot_astroid(b=1, c=1, beta=3, gamma=3, hc=1, rotation=0, resolution=361, angle_range=(0, 6.283185307179586), ax=None, **kwargs)#
flatspin.plotting.plot_color_wheel(angles=8, angle_start=0, angle_range=360, radians=False, center_radius=0.13, center_color='white', ax=None, **kwargs)#