Note
Go to the end to download the full example code.
Pivot Charts without Stacking#
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 compare series per point on the x-axis horizontally:
Each category can be manually plotted as a
seriesby specifying thecategory_nameparameter as the value along with thepivot_column_nameto use for the seriesThe
column_nameshould remain the numerical column to plot. The data will for the series will be filtered to the specificcategory_nameautomaticallyThe
is_stackedparameter should be set toFalseor not set, as this is the default behaviorThe 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",
pivot_column_name="region",
),
series(
column_name="ios_dl_idx",
category_name="China",
color="light-grey",
mode="bar",
pivot_column_name="region",
),
series(
column_name="ios_dl_idx",
category_name="India",
color="orange",
mode="bar",
pivot_column_name="region",
),
],
)
fig
Total running time of the script: (0 minutes 0.024 seconds)