.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_sankey.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_gallery_plot_sankey.py: ============== Sankey diagram ============== .. GENERATED FROM PYTHON SOURCE LINES 9-31 Read in example data and show a summary *************************************** This gallery uses a small selection of the data compiled for the IPCC's *Special Report on Global Warming of 1.5°C* (SR15_). The complete scenario ensemble data is publicly available from the `IAMC 1.5°C Scenario Explorer and Data hosted by IIASA`_. Please read the License_ of the IAMC 1.5°C Scenario Explorer before using the full scenario data for scientific analyis or other work. .. _SR15: http://ipcc.ch/sr15/ .. _`IAMC 1.5°C Scenario Explorer and Data hosted by IIASA` : https://data.ece.iiasa.ac.at/iamc-1.5c-explorer .. _License : https://data.ece.iiasa.ac.at/iamc-1.5c-explorer/#/license If you haven't cloned the **pyam** GitHub repository to your machine, you can download the data file from https://github.com/IAMconsortium/pyam/tree/main/docs/examples_source Make sure to place the data file in the same folder as this script/notebook. .. GENERATED FROM PYTHON SOURCE LINES 31-39 .. code-block:: Python import plotly import pyam df = pyam.IamDataFrame("sankey_data.csv") df .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/pyam-iamc/checkouts/stable/pyam/utils.py:318: FutureWarning: The previous implementation of stack is deprecated and will be removed in a future version of pandas. See the What's New notes for pandas 2.1.0 for details. Specify future_stack=True to adopt the new implementation and silence this warning. Index: * model : IMAGE 3.0.1 (1) * scenario : CD-LINKS_NPi2020_1000 (1) Timeseries data coordinates: region : World (1) variable : Final Energy|Electricity, ... (9) unit : EJ/yr (1) year : 2005, 2010, 2015, 2020, 2025, 2030, 2035, 2040, ... 2100 (15) .. GENERATED FROM PYTHON SOURCE LINES 40-55 A simple Sankey diagram *********************** We show a Sankey diagram of a subset of the energy system in the 'CD-LINKS_NPi2020_1000' scenario implemented by the 'REMIND-MAgPIE 1.7-3.0' model. The :meth:`~pyam.figures.sankey` function takes a dictionary to define flows, sources and targets: .. code-block:: python { variable: (source, target), } .. GENERATED FROM PYTHON SOURCE LINES 55-83 .. code-block:: Python sankey_mapping = { "Primary Energy|Coal": ("Coal Mining", "Coal Trade & Power Generation"), "Primary Energy|Gas": ("Natural Gas Extraction", "Gas Network & Power Generation"), "Secondary Energy|Electricity|Non-Biomass Renewables": ( "Non-Biomass Renewables", "Electricity Grid", ), "Secondary Energy|Electricity|Nuclear": ("Nuclear", "Electricity Grid"), "Secondary Energy|Electricity|Coal": ( "Coal Trade & Power Generation", "Electricity Grid", ), "Secondary Energy|Electricity|Gas": ( "Gas Network & Power Generation", "Electricity Grid", ), "Final Energy|Electricity": ("Electricity Grid", "Electricity Demand"), "Final Energy|Solids|Coal": ( "Coal Trade & Power Generation", "Non-Electricity Coal Demand", ), "Final Energy|Gases": ("Gas Network & Power Generation", "Gas Demand"), } fig = df.filter(year=2050).plot.sankey(mapping=sankey_mapping) # calling `show()` is necessary to have the thumbnail in the gallery overview plotly.io.show(fig) .. raw:: html :file: images/sphx_glr_plot_sankey_001.html .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/pyam-iamc/checkouts/stable/pyam/figures.py:58: FutureWarning: Downcasting behavior in `replace` is deprecated and will be removed in a future version. To retain the old behavior, explicitly call `result.infer_objects(copy=False)`. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)` .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.910 seconds) .. _sphx_glr_download_gallery_plot_sankey.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sankey.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sankey.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_