Plotting¶
-
turbulucid.core.plotting.
add_colorbar
(data, aspect=20, padFraction=0.5, **kwargs)¶ Add a vertical colorbar to an image plot.
Parameters: - data – The data with a .axes attribute.
- aspect (float, optional) – The ratio between the height and the width of the colorbar.
- padFraction (float, optional) – The horizontal distance between the figure and the colorbar as a fraction of the width of the colorbar.
Returns: The colorbar object
Return type: colorbar
-
turbulucid.core.plotting.
plot_boundaries
(case, scaleX=1, scaleY=1, **kwargs)¶ Plot the boundaries the domain.
Parameters: - case (Case) – The case to draw the boundaries for.
- scaleX (float, optional) – A scaling factor for the abscissa.
- scaleY (float, optional) – A scaling factor for the ordinate.
- **kwargs – Additional options to pass to pyplot.tricontour.
Raises: ValueError
– If one or both scaling factors are non-positive.Returns: Collection of line segments defining the boundary.
Return type: LineCollection
-
turbulucid.core.plotting.
plot_contour
(case, field, value, scaleX=1, scaleY=1, **kwargs)¶ Plot a contour plot of a scalar field.
The cell data is first interpolated to points in order to use vtkContourFilter to extract the contour line. The kwargs are passed to the constructor of a LineCollection and can be used to customize the plotted line, e.g. its colour.
Parameters: - case (Case) – The case to draw the boundaries for.
- field (string) – The field to extract the contour from.
- value (float) – The value associated with the contour.
- scaleX (float, optional) – A scaling factor for the abscissa.
- scaleY (float, optional) – A scaling factor for the ordinate.
- **kwargs – Additional options to pass to pyplot.tricontour.
Raises: ValueError
– If one or both scaling factors are non-positive.Returns: Collection of line segments defining the contour line.
Return type: LineCollection
-
turbulucid.core.plotting.
plot_field
(case, field, scaleX=1, scaleY=1, xlim=None, ylim=None, plotBoundaries=True, colorbar=True, **kwargs)¶ Plot a field.
This function uses a matplotlib PatchCollection to compose the plot. Additional customization parameters can be passed to the constructor of the PatchCollection via kwargs. In particular, cmap can be used to set the colormap and edgecolor to color the edges of the cells.
Parameters: - case (Case) – The case that the vector field used for the streamlines belongs to.
- field (str or ndarray) – The scalar field that will be plotted. Either a string with the name of the field as found in the case or an ndarray with the data.
- scaleX (float, optional) – A scaling factor for the abscissa.
- scaleY (float, optional) – A scaling factor for the ordinate.
- xlim (list with two elements) – Limits for the plotted data in the x direction. Defaults to no limits.
- ylim (list with two elements) – Limits for the plotted data in the y direction. Defaults to no limits.
- plotBoundaries (bool, optional) – Whether to plot the boundary of the geometry as a black line.
- colorbar (bool, optional) – Whether to add a vertical colorbar to the right of the plot.
- **kwargs – Additional arguments to be passed to PatchCollection constructor.
Raises: TypeError
– If field is neither a string or and ndarray.ValueError
– If the field to be plotted has more dimensions than one. If one or both scaling factors are non-positive.
Returns: The collection of polygons defining the cells.
Return type: PatchCollection
-
turbulucid.core.plotting.
plot_streamlines
(case, field, colorField=None, scaleX=1, scaleY=1, planeResolution=None, plotBoundaries=True, **kwargs)¶ Produce a streamline plot.
This function wraps pyplot.streamplot. See that functions documentation for additional customization parameters.
Parameters: - case (Case) – The case that the vector field used for the streamlines belongs to.
- field (str or ndarray) – The vector field used for computing the streamlines. Either a string with the name of the field as found in the case or an ndarray with the data.
- colorField (string or ndarray) – Data used to colour the vectors, either name of the field or an array.
- normalize (bool, optional) – Whether to normalize the the length of the vectors. Default is False.
- scaleX (float, optional) – A scaling factor for the abscissa.
- scaleY (float, optional) – A scaling factor for the ordinate.
- planeResolution (2-tuple, optional) – Sets the amount of sampling points in the x and y directions. Note that this does not control the density of the streamlines.
- plotBoundaries (bool, optional) – Whether to plot the boundary of the geometry as a black line.
- **kwargs – Additional arguments to be passed to pyplot.quiver.
Raises: TypeError
– If field is neither a string or and ndarray.ValueError
– If the data to be plotted has less dimensions than two. If one or both scaling factors are non-positive.
Returns: As returned by pyplot.streamplot.
Return type: StreamPlotSet
-
turbulucid.core.plotting.
plot_vectors
(case, field, colorField=None, normalize=False, scaleX=1, scaleY=1, sampleByPlane=False, planeResolution=None, plotBoundaries=True, **kwargs)¶ Plot a vector field.
This function wraps pyplot.quiver. See that function’s documentation for additional keyword argumnets.
Parameters: - case (Case) – The case that the vector field belongs to.
- field (str or ndarray) – Either a string with the name of the field as found in the case or an ndarray with the data.
- colorField (string or ndarray) – Data used to colour the vectors, either name of the field or an array.
- normalize (bool, optional) – Whether to normalize the the length of the vectors. Default is False.
- scaleX (float, optional) – A scaling factor for the abscissa.
- scaleY (float, optional) – A scaling factor for the ordinate.
- sampleByPlane (bool, optional) – Instead of using the cell-centre coordinates use points equally distributed over a plane overlayed on the geometry.
- planeResolution (2-tuple, optional) – Only needed in case sampleByPlane is True. Sets the amount of sampling points in the x and y directions.
- plotBoundaries (bool, optional) – Whether to plot the boundary of the geometry as a black line.
- **kwargs – Additional arguments to be passed to pyplot.quiver.
Raises: TypeError
– If field is neither a string or and ndarray.ValueError
– If the data to be plotted has less dimensions than two. If one or both scaling factors are non-positive.
Returns: As returned by pyplot.quiver.
Return type: Quiver