Note
Go to the end to download the full example code.
Stacked Pivot Charts#
Plotting charts where the input data is aggregated by a categorical column can be pivoted using pivot_column_name in the series function.
When pivoting and wanting to stack each series per point on the x-axis:
Each category can be manually plotted as a
seriesby specifying thecategory_nameparameter and thepivot_column_nameto use for the seriesThe
column_nameshould remain as the numerical column to plot. The data will for the series will be filtered to the specificcategory_nameautomaticallyThe
is_stackedparameter can control if the series are stacked vertically or kept side by side (default)When
is_stacked=True, Axis min/max are automatically calculated as the sum of all series on the specified y1 or y2 axisThe order of the series in the legend and in the graph is based on the order of elements in
chart_seriesparameter.
import pandas as pd
from visualization_toolkit.helpers.plotly import chart, axis, series
fig = chart(
pdf,
x_axis=axis(column_name="fiscal_qy", label="Fiscal Quarter"),
y1_axis=axis(label="Downloads", axis_type="number", axis_min=0),
chart_series=[
series(
column_name="ios_dl_idx",
category_name="UCAN",
color="light-blue",
mode="bar",
is_stacked=True,
pivot_column_name="region",
),
series(
column_name="ios_dl_idx",
category_name="China",
color="light-grey",
mode="bar",
is_stacked=True,
pivot_column_name="region",
),
series(
column_name="ios_dl_idx",
category_name="India",
color="orange",
mode="bar",
is_stacked=True,
pivot_column_name="region",
),
],
)
fig
Total running time of the script: (0 minutes 0.026 seconds)