.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "recipes/pivoting/plot_pivot_chart_stacked.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_pivoting_plot_pivot_chart_stacked.py: 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 ``series`` by specifying the ``category_name`` parameter and the ``pivot_column_name`` to use for the series - The ``column_name`` should remain as the numerical column to plot. The data will for the series will be filtered to the specific ``category_name`` automatically - The ``is_stacked`` parameter 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 axis - The order of the series in the legend and in the graph is based on the order of elements in ``chart_series`` parameter. .. GENERATED FROM PYTHON SOURCE LINES 17-55 .. raw:: html


.. code-block:: Python 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 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.026 seconds) .. _sphx_glr_download_recipes_pivoting_plot_pivot_chart_stacked.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pivot_chart_stacked.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pivot_chart_stacked.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_pivot_chart_stacked.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_