-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a sankey-example to the plotting gallery (#472)
- Loading branch information
1 parent
5985072
commit 11849b4
Showing
13 changed files
with
161 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
============== | ||
Sankey diagram | ||
============== | ||
""" | ||
############################### | ||
# 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.ene.iiasa.ac.at/iamc-1.5c-explorer | ||
# | ||
# .. _License : https://data.ene.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/master/doc/source/examples_source | ||
# | ||
# Make sure to place the data file in the same folder as this script/notebook. | ||
|
||
import pyam | ||
import plotly | ||
df = pyam.IamDataFrame('sankey_data.csv') | ||
df | ||
|
||
############################### | ||
# 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), | ||
# } | ||
|
||
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).sankey(mapping=sankey_mapping) | ||
# calling `show()` is necessary to have the thumbnail in the gallery overview | ||
plotly.io.show(fig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.