.. _sphx_glr_examples_plot_pie.py: ======================== Plot Data as a Pie Chart ======================== .. code-block:: python # sphinx_gallery_thumbnail_number = 3 import matplotlib.pyplot as plt import pyam Read in some example data .. code-block:: python fname = 'data.csv' df = pyam.IamDataFrame(fname, encoding='ISO-8859-1') We generated a simple stacked bar chart as below .. code-block:: python data = df.filter({'variable': 'Emissions|CO2|*', 'level': 0, 'year': 2050, 'region': 'World'}) fig, ax = plt.subplots(figsize=(10, 10)) data.pie_plot(ax=ax) fig.subplots_adjust(right=0.75, left=0.3) plt.show() .. image:: /examples/images/sphx_glr_plot_pie_001.png :align: center Sometimes a legend is preferable to labels, we can use those instead. .. code-block:: python fig, ax = plt.subplots(figsize=(10, 10)) data.pie_plot(ax=ax, labels=None, legend=True) fig.subplots_adjust(right=0.55, left=-0.05) plt.show() .. image:: /examples/images/sphx_glr_plot_pie_002.png :align: center We don't just have to plot variables, any data or metadata associated with the IamDataFrame can be used. .. code-block:: python data = (df .filter({'variable': 'Emissions|CO2', 'year': 2050}) .filter({'region': 'World'}, keep=False) ) data.pie_plot(category='region', cmap='tab20') plt.show() .. image:: /examples/images/sphx_glr_plot_pie_003.png :align: center **Total running time of the script:** ( 0 minutes 0.115 seconds) .. only :: html .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: plot_pie.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_pie.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_