pyvista.plotting.charts.StackPlot

Contents

pyvista.plotting.charts.StackPlot#

class StackPlot(chart, x, ys, colors=None, labels=None)[source]#

Class representing a 2D stack plot.

Users should typically not directly create new plot instances, but use the dedicated 2D chart’s plotting methods.

Parameters:
chartChart2D

The chart containing this plot.

xarray_like

X coordinates of the points outlining the stacks (areas) to draw.

yssequence[array_like]

Size of the stacks (areas) to draw at the corresponding X coordinates. Each sequence defines the sizes of one stack (area), which are stacked on top of each other.

colorssequence[ColorLike], optional

Color of the stacks (areas) drawn in this plot. Any color parsable by pyvista.Color is allowed.

labelssequence[str], default: []

Label for each stack (area) drawn in this plot, as shown in the chart’s legend.

Examples

Create a stack plot showing the amount of vehicles sold per type.

>>> import pyvista as pv
>>> import numpy as np
>>> year = [f'{y}' for y in np.arange(2011, 2021)]
>>> x = np.arange(len(year))
>>> n_e = [1739, 4925, 9515, 21727, 31452, 29926, 40648, 57761, 76370, 93702]
>>> n_h = [5563, 7642, 11937, 13905, 22807, 46700, 60875, 53689, 46650, 50321]
>>> n_f = [
...     166556,
...     157249,
...     151552,
...     138183,
...     129669,
...     113985,
...     92965,
...     73683,
...     57097,
...     29499,
... ]
>>> chart = pv.Chart2D()
>>> plot = chart.stack(x, [n_e, n_h, n_f])
>>> plot.labels = ['Electric', 'Hybrid', 'Fossil']
>>> chart.x_axis.label = 'Year'
>>> chart.x_axis.tick_locations = x
>>> chart.x_axis.tick_labels = year
>>> chart.y_axis.label = 'New car sales'
>>> chart.show()
../../../../_images/pyvista-plotting-charts-StackPlot-2_00_00.png

Methods

StackPlot.toggle()

Toggle the plot's visibility.

StackPlot.update(x, ys)

Update the locations and/or size of the stacks (areas) in this plot.

Attributes

StackPlot.brush

Brush object controlling how shapes in this plot are filled.

StackPlot.color

Return or set the plot's color.

StackPlot.color_scheme

Return or set the plot's color scheme.

StackPlot.colors

Return or set the plot's colors.

StackPlot.label

Return or set the this plot's label, as shown in the chart's legend.

StackPlot.labels

Return or set the this plot's labels, as shown in the chart's legend.

StackPlot.line_style

Return or set the line style of all lines drawn in this plot.

StackPlot.line_width

Return or set the line width of all lines drawn in this plot.

StackPlot.pen

Pen object controlling how lines in this plot are drawn.

StackPlot.visible

Return or set the this plot's visibility.

StackPlot.x

Retrieve the X coordinates of the drawn stacks.

StackPlot.ys

Retrieve the sizes of the drawn stacks.