pyvista.ChartMPL#

class ChartMPL(figure=None, size=(1, 1), loc=(0, 0), redraw_on_render=True)[source]#

Create new chart from an existing matplotlib figure.

Parameters:
figurematplotlib.figure.Figure, optional

The matplotlib figure to draw. If no figure is provided ( None ), a new figure is created.

sizesequence[float], default: (1, 1)

Size of the chart in normalized coordinates. A size of (0, 0) is invisible, a size of (1, 1) occupies the whole renderer’s width and height.

locsequence[float], default: (0, 0)

Location of the chart (its bottom left corner) in normalized coordinates. A location of (0, 0) corresponds to the renderer’s bottom left corner, a location of (1, 1) corresponds to the renderer’s top right corner.

redraw_on_renderbool, default: True

Flag indicating whether the chart should be redrawn when the plotter is rendered. For static charts, setting this to False can improve performance.

Examples

Plot streamlines of a vector field with varying colors (based on this example).

>>> import pyvista as pv
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> w = 3
>>> Y, X = np.mgrid[-w:w:100j, -w:w:100j]
>>> U = -1 - X**2 + Y
>>> V = 1 + X - Y**2
>>> speed = np.sqrt(U**2 + V**2)
>>> f, ax = plt.subplots()
>>> strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn')
>>> _ = f.colorbar(strm.lines)
>>> _ = ax.set_title('Streamplot with varying Color')
>>> plt.tight_layout()
>>> chart = pv.ChartMPL(f)
>>> chart.show()
../../../../_images/pyvista-ChartMPL-2_00_00.png

Methods

ChartMPL.show([interactive, off_screen, ...])

Show this chart in a self contained plotter.

ChartMPL.toggle()

Toggle the chart's visibility.

Attributes

ChartMPL.active_background_color

Return or set the chart's background color in interactive mode.

ChartMPL.active_border_color

Return or set the chart's border color in interactive mode.

ChartMPL.background_color

Return or set the chart's background color.

ChartMPL.background_texture

Return or set the chart's background texture.

ChartMPL.border_color

Return or set the chart's border color.

ChartMPL.border_style

Return or set the chart's border style.

ChartMPL.border_width

Return or set the chart's border width.

ChartMPL.figure

Retrieve the matplotlib figure associated with this chart.

ChartMPL.legend_visible

Return or set the visibility of the chart's legend.

ChartMPL.loc

Return or set the chart position in normalized coordinates.

ChartMPL.position

Chart position w.r.t the bottom left corner (in pixels).

ChartMPL.redraw_on_render

Return or set the chart's redraw-on-render behavior.

ChartMPL.size

Return or set the chart size in normalized coordinates.

ChartMPL.title

Return or set the chart's title.

ChartMPL.visible

Return or set the chart's visibility.