.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\plotly\demo_sankey_diagram.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_11_demos_python_packages_plotly_demo_sankey_diagram.py: Sankey diagram ============== This demo shows how to use the Python ``plotly`` package under itom. In order to show plotly outputs in itom figures, it is only necessary to import the ``itomPlotlyRenderer`` module once at the beginning of your script. This adds an itom specific renderer to Plotly and uses it as default. The plotly outputs are then shown in an itom designerPlugin with the name ``plotlyPlot``. .. GENERATED FROM PYTHON SOURCE LINES 13-66 .. code-block:: Python import itomPlotlyRenderer import plotly.graph_objects as go import json with open("sankey_energy.json") as file: data = json.load(file) # override gray link colors with 'source' colors opacity = 0.4 # change 'magenta' to its 'rgba' value to add opacity data["data"][0]["node"]["color"] = [ "rgba(255,0,255, 0.8)" if color == "magenta" else color for color in data["data"][0]["node"]["color"] ] data["data"][0]["link"]["color"] = [ data["data"][0]["node"]["color"][src].replace("0.8", str(opacity)) for src in data["data"][0]["link"]["source"] ] fig = go.Figure( data=[ go.Sankey( valueformat=".0f", valuesuffix="TWh", # Define nodes node=dict( pad=15, thickness=15, line=dict(color="black", width=0.5), label=data["data"][0]["node"]["label"], color=data["data"][0]["node"]["color"], ), # Add links link=dict( source=data["data"][0]["link"]["source"], target=data["data"][0]["link"]["target"], value=data["data"][0]["link"]["value"], label=data["data"][0]["link"]["label"], color=data["data"][0]["link"]["color"], ), ) ] ) fig.update_layout( title_text="Energy forecast for 2050
Source: Department of Energy & Climate Change, " "Tom Counsell via Mike Bostock", font_size=10, ) fig.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.204 seconds) .. _sphx_glr_download_11_demos_python_packages_plotly_demo_sankey_diagram.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_sankey_diagram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_sankey_diagram.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_sankey_diagram.zip `