pyvista.plotting.charts.BarPlot

Contents

pyvista.plotting.charts.BarPlot#

class BarPlot(chart, x, y, color=None, orientation='V', label=None)[source]#

Class representing a 2D bar 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

Positions (along the x-axis for a vertical orientation, along the y-axis for a horizontal orientation) of the bars to draw.

yarray_like

Size of the bars to draw. Multiple bars can be stacked by passing a sequence of sequences.

colorColorLike, default: “b”

Color of the bars drawn in this plot. Any color parsable by pyvista.Color is allowed.

orientationstr, default: “V”

Orientation of the bars drawn in this plot. Either "H" for an horizontal orientation or "V" for a vertical orientation.

labelstr, default: “”

Label of this plot, as shown in the chart’s legend.

Examples

Create a stacked bar chart showing the average time spent on activities throughout the week.

>>> import pyvista as pv
>>> import numpy as np
>>> x = np.arange(1, 8)
>>> y_s = [7, 8, 7.5, 8, 7.5, 9, 10]
>>> y_h = [2, 3, 2, 2.5, 1.5, 4, 6.5]
>>> y_w = [8, 8, 7, 8, 7, 0, 0]
>>> y_r = [5, 2.5, 4.5, 3.5, 6, 9, 6.5]
>>> y_t = [2, 2.5, 3, 2, 2, 2, 1]
>>> labels = ['Sleep', 'Household', 'Work', 'Relax', 'Transport']
>>> chart = pv.Chart2D()
>>> _ = chart.bar(x, [y_s, y_h, y_w, y_r, y_t], label=labels)
>>> chart.x_axis.tick_locations = x
>>> chart.x_axis.tick_labels = [
...     'Mon',
...     'Tue',
...     'Wed',
...     'Thu',
...     'Fri',
...     'Sat',
...     'Sun',
... ]
>>> chart.x_label = 'Day of week'
>>> chart.y_label = 'Average time spent'
>>> chart.grid = False  # Disable the grid lines
>>> chart.show()
../../../../_images/pyvista-plotting-charts-BarPlot-2_00_00.png

Methods

BarPlot.toggle()

Toggle the plot's visibility.

BarPlot.update(x, y)

Update the positions and/or size of the bars in this plot.

Attributes

BarPlot.brush

Brush object controlling how shapes in this plot are filled.

BarPlot.color

Return or set the plot's color.

BarPlot.color_scheme

Return or set the plot's color scheme.

BarPlot.colors

Return or set the plot's colors.

BarPlot.label

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

BarPlot.labels

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

BarPlot.line_style

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

BarPlot.line_width

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

BarPlot.orientation

Return or set the orientation of the bars in this plot.

BarPlot.pen

Pen object controlling how lines in this plot are drawn.

BarPlot.visible

Return or set the this plot's visibility.

BarPlot.x

Retrieve the positions of the drawn bars.

BarPlot.y

Retrieve the sizes of the drawn bars.