.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "recipes/bar_chart/plot_clustered_bar_chart.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_recipes_bar_chart_plot_clustered_bar_chart.py: 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 ``series`` can be plotted and it must set a ``pivot_column_name`` with ``include_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 ``customdata`` property of the trace. - ``category_sort_column_name`` can 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 ``hovertemplate`` is used depending on the nature of chart to improve the hover experience for users. This can be provided to ``extra_options``. .. GENERATED FROM PYTHON SOURCE LINES 15-46 .. raw:: html


.. code-block:: Python 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": ( """ %{x}
Month: %{customdata[0]|%b %Y}
Spend: %{y}
""" ).strip(), }, ), ], theme=ATLAS_THEME, ) fig .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.078 seconds) .. _sphx_glr_download_recipes_bar_chart_plot_clustered_bar_chart.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_clustered_bar_chart.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_clustered_bar_chart.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_clustered_bar_chart.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_