Charts (Pie and Bar)

The term “chart” is used for diagrams where the x value is qualitative. This includes Pie charts and bar charts.


BarChart

A bar chart. The Diagram is ziaplot.charts.bar.BarChart, with ziaplot.charts.bar.Bar instances added to it:

with zp.BarChart().axesnames('Month', 'Number').title('Single Series Bar Chart'):
    zp.Bar(3).name('January')
    zp.Bar(5).name('February')
    zp.Bar(4).name('March')
    zp.Bar(8).name('April')
_images/charts_1_0.svg

Or the fromdict class method creates the chart from a dictionary.

items = {'January': 4,
         'February': 6,
         'March': 2,
         'April': 5}
zp.BarChart.fromdict(items).axesnames('Month', 'Number').title('Bar Chart From Dictionary')
_images/charts_2_0.svg

BarChartGrouped

A bar chart with multiple bars at each x value. The same-colored bars form a group or “series”.

with zp.BarChartGrouped(groups=['January', 'February', 'March', 'April']):
    zp.BarSeries(4, 4, 5, 6).name('Apple')
    zp.BarSeries(3, 4, 4, 5).name('Blueberry')
    zp.BarSeries(2, 1, 5, 4).name('Cherry')
_images/charts_3_0.svg

ziaplot.charts.bar.BarChartGrouped ziaplot.charts.bar.BarSeries

BarChartGroupedHoriz

A grouped bar chart with horizontal bars.

with zp.BarChartGroupedHoriz(groups=['January', 'February', 'March', 'April']):
    zp.BarSeries(4, 4, 5, 6).name('Apple')
    zp.BarSeries(3, 4, 4, 5).name('Blueberry')
    zp.BarSeries(2, 1, 5, 4).name('Cherry')
_images/charts_4_0.svg

Pie

A pie chart. The Diagram is ziaplot.charts.pie.Pie, with ziaplot.charts.pie.PieSlice added to it.

with zp.Pie():
    zp.PieSlice(3).name('a')
    zp.PieSlice(10).name('b')
    zp.PieSlice(5).name('c')
_images/charts_5_0.svg

Note

The slice values are normalized so the pie will always fill to 100%.

Pie Charts may also be made from dictionaries or from lists.

zp.Pie().fromdict({'a': 20, 'b': 30, 'c': 40, 'd': 10})
_images/charts_6_0.svg
zp.Pie().fromlist((3, 4, 2, 2, 5, 1))
_images/charts_7_0.svg

Tip

Use the labelmode parameter to change the label displayed outside each slice. Options are name, value, percent, or none.

with zp.Pie(labelmode='percent'):
    zp.PieSlice(3).name('a')
    zp.PieSlice(10).name('b')
    zp.PieSlice(5).name('c')
_images/charts_8_0.svg

Tip

Use .extrude() to pull a slice away from the center of the pie.

with zp.Pie(labelmode='value'):
    zp.PieSlice(3).name('a').extrude()
    zp.PieSlice(10).name('b')
    zp.PieSlice(5).name('c')
_images/charts_9_0.svg