How to use matplotlib and plotly in WASDI

Matplotlib and plotly are two commonly used python packages for plotting. If you wish to use them in WASDI notebooks, then this page is for you.

Prerequisites

To run this code you need:
  • A valid WASDI Account

  • A workspace

  • a Jupyter Notebook running in that workspace

If this is not clear, you probably need to take a look to the Jupyter Notebook Tutorial before.

matplotlib recipe

Install the library

pip install matplotlib -U

And test it:

import matplotlib.pyplot as plt

radius = [1.0, 2.0, 3.0, 4.0]
area = [3.14159, 12.56636, 28.27431, 50.26544]

plt.plot(radius, area)
plt.show()

You should be able to see a simple graph like this one:

../_images/matplotlib.png

If you can see the images, then good, you don’t need to re-execute the pip install block in the future. Otherwise reach out for help on the support forum on our discord server.

plotly recipe

Install the library

pip install plotly -U

And then test it:

# we'll use this package to make plotly work with Jupyter notebooks in WASDI
import plotly.io as pio
import plotly.graph_objs as go

# Set the default renderer to 'iframe'
pio.renderers.default = 'iframe'

fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="A Figure Displayed with fig.show()"
)
fig.show()

You should be able to see a bar plot like this one:

../_images/plotly.png

If you can see the images, then good, you don’t need to re-execute the pip install block in the future. Otherwise reach out for help on the support forum on our discord server.

What it does:

In both cases, we first installed the required package and then we plotted a test graph to check it worked properly.