contourpy.util¶
This module includes Renderer classes for both Bokeh and Matplotlib to visualise contours
calculated by ContourPy. These renderers are used internally in the test suite and for examples in
this documentation. Please use them to experiment with ContourPy, but it is recommended that you
don’t use them in downstream projects as they are liable to change at short notice without a
formal deprecation period. Instead use Bokeh and Matplotlib directly as they both use
ContourPy for their contour calculations and they provide much richer visualisation functionality.
- class contourpy.util.renderer.Renderer[source]¶
Abstract base class for renderers.
- multi_filled(multi_filled, fill_type, ax=0, color=None, **kwargs)[source]¶
Plot multiple sets of filled contours on a single axes.
- Parameters:
multi_filled (list of filled contour arrays) – Multiple filled contour sets as returned by
ContourGenerator.multi_filled().fill_type (FillType or str) – Type of filled data as returned by
fill_type, or string equivalent.ax (int or Renderer-specific axes or figure object, optional) – Which axes to plot on, default
0.color (str or None, optional) – If a string color then this same color is used for all filled contours. If
None, the default, then the filled contour sets use colors from thetab10colormap in order, wrapping around to the beginning if more than 10 sets of filled contours are rendered.kwargs – All other keyword argument are passed on to
Renderer.filled()unchanged.
Added in version 1.3.0.
- multi_lines(multi_lines, line_type, ax=0, color=None, **kwargs)[source]¶
Plot multiple sets of contour lines on a single axes.
- Parameters:
multi_lines (list of contour line arrays) – Multiple contour line sets as returned by
ContourGenerator.multi_lines().line_type (LineType or str) – Type of line data as returned by
line_type, or string equivalent.ax (int or Renderer-specific axes or figure object, optional) – Which axes to plot on, default
0.color (str or None, optional) – If a string color then this same color is used for all lines. If
None, the default, then the line sets use colors from thetab10colormap in order, wrapping around to the beginning if more than 10 sets of lines are rendered.kwargs – All other keyword argument are passed on to
Renderer.lines()unchanged.
Added in version 1.3.0.
- class contourpy.util.mpl_renderer.MplRenderer(nrows=1, ncols=1, figsize=(9, 9), show_frame=True, backend=None, gridspec_kw=None)[source]¶
Utility renderer using Matplotlib to render a grid of plots over the same (x, y) range.
- Parameters:
nrows (int, optional) – Number of rows of plots, default
1.ncols (int, optional) – Number of columns of plots, default
1.figsize (tuple(float, float), optional) – Figure size in inches, default
(9, 9).show_frame (bool, optional) – Whether to show frame and axes ticks, default
True.backend (str, optional) – Matplotlib backend to use or
Nonefor default backend. DefaultNone.gridspec_kw (dict, optional) – Gridspec keyword arguments to pass to
plt.subplots, default None.
- filled(filled, fill_type, ax=0, color='C0', alpha=0.7)[source]¶
Plot filled contours on a single Axes.
- Parameters:
filled (sequence of arrays) – Filled contour data as returned by
filled().fill_type (FillType or str) – Type of
filled()data as returned byfill_type, or string equivalentax (int or Maplotlib Axes, optional) – Which axes to plot on, default
0.color (str, optional) – Color to plot with. May be a string color or the letter
"C"followed by an integer in the range"C0"to"C9"to use a color from thetab10colormap. Default"C0".alpha (float, optional) – Opacity to plot with, default
0.7.
- grid(x, y, ax=0, color='black', alpha=0.1, point_color=None, quad_as_tri_alpha=0)[source]¶
Plot quad grid lines on a single Axes.
- Parameters:
x (array-like of shape (ny, nx) or (nx,)) – The x-coordinates of the grid points.
y (array-like of shape (ny, nx) or (ny,)) – The y-coordinates of the grid points.
ax (int or Matplotlib Axes, optional) – Which Axes to plot on, default
0.color (str, optional) – Color to plot grid lines, default
"black".alpha (float, optional) – Opacity to plot lines with, default
0.1.point_color (str, optional) – Color to plot grid points or
Noneif grid points should not be plotted, defaultNone.quad_as_tri_alpha (float, optional) – Opacity to plot
quad_as_trigrid, default 0.
Colors may be a string color or the letter
"C"followed by an integer in the range"C0"to"C9"to use a color from thetab10colormap.Warning
quad_as_tri_alpha > 0plots all quads as though they are unmasked.
- lines(lines, line_type, ax=0, color='C0', alpha=1.0, linewidth=1)[source]¶
Plot contour lines on a single Axes.
- Parameters:
lines (sequence of arrays) – Contour line data as returned by
lines().line_type (LineType or str) – Type of
lines()data as returned byline_type, or string equivalent.ax (int or Matplotlib Axes, optional) – Which Axes to plot on, default
0.color (str, optional) – Color to plot lines. May be a string color or the letter
"C"followed by an integer in the range"C0"to"C9"to use a color from thetab10colormap. Default"C0".alpha (float, optional) – Opacity to plot lines with, default
1.0.linewidth (float, optional) – Width of lines, default
1.
- mask(x, y, z, ax=0, color='black')[source]¶
Plot masked out grid points as circles on a single Axes.
- Parameters:
x (array-like of shape (ny, nx) or (nx,)) – The x-coordinates of the grid points.
y (array-like of shape (ny, nx) or (ny,)) – The y-coordinates of the grid points.
z (masked array of shape (ny, nx) – z-values.
ax (int or Matplotlib Axes, optional) – Which Axes to plot on, default
0.color (str, optional) – Circle color, default
"black".
- save(filename, transparent=False)[source]¶
Save plots to SVG or PNG file.
- Parameters:
filename (str) – Filename to save to.
transparent (bool, optional) – Whether background should be transparent, default
False.
- save_to_buffer()[source]¶
Save plots to an
io.BytesIObuffer.- Returns:
PNG image buffer.
- Return type:
BytesIO
- title(title, ax=0, color=None)[source]¶
Set the title of a single Axes.
- Parameters:
title (str) – Title text.
ax (int or Matplotlib Axes, optional) – Which Axes to set the title of, default
0.color (str, optional) – Color to set title. May be a string color or the letter
"C"followed by an integer in the range"C0"to"C9"to use a color from thetab10colormap. Default isNonewhich uses Matplotlib’s default title color that depends on the stylesheet in use.
- z_values(x, y, z, ax=0, color='green', fmt='.1f', quad_as_tri=False)[source]¶
Show
zvalues on a single Axes.- Parameters:
x (array-like of shape (ny, nx) or (nx,)) – The x-coordinates of the grid points.
y (array-like of shape (ny, nx) or (ny,)) – The y-coordinates of the grid points.
z (array-like of shape (ny, nx) – z-values.
ax (int or Matplotlib Axes, optional) – Which Axes to plot on, default
0.color (str, optional) – Color of added text. May be a string color or the letter
"C"followed by an integer in the range"C0"to"C9"to use a color from thetab10colormap. Default"green".fmt (str, optional) – Format to display z-values, default
".1f".quad_as_tri (bool, optional) – Whether to show z-values at the
quad_as_tricenters of quads.
Warning
quad_as_tri=Trueshows z-values for all quads, even if masked.