Note
Go to the end to download the full example code.
Clustered Bar Chart#
Bar charts can be clustered by a categorical column while plotting values on a time-series for each “category”.
This can be created by setting mode=clustered_bar in a series of the chart.
Only 1
seriescan be plotted and it must set apivot_column_namewithinclude_all_categories=True.The pivot column name is used to define each bar within a cluster. Typically, this will be a date-type column. These values will be stored in the
customdataproperty of the trace.category_sort_column_namecan define a sort order for bars within each cluster based on the values of that column.The clusters will share the same y-axis.
It is recommended that a custom
hovertemplateis used depending on the nature of chart to improve the hover experience for users. This can be provided toextra_options.
import pandas as pd
from visualization_toolkit.helpers.plotly import chart, axis, series
from visualization_toolkit.helpers.plotly.theme import ATLAS_THEME
fig = chart(
pdf,
x_axis=axis(column_name="vendor", axis_type="category"),
y1_axis=axis(label="Spend", axis_type="currency"),
chart_series=[
series(
column_name="spend",
label="Spend",
mode="clustered_bar",
pivot_column_name="month",
category_sort_column_name="month",
include_all_categories=True,
extra_options={
"hovertemplate": (
"""
<b>%{x}</b><br><span style='color: #9E9E9E;'>Month: </span>%{customdata[0]|%b %Y}<br><span style='color: #9E9E9E;'>Spend: </span>%{y}<br><extra></extra>
"""
).strip(),
},
),
],
theme=ATLAS_THEME,
)
fig
Total running time of the script: (0 minutes 0.078 seconds)