2. Plotly Tutorial

Plot.ly is a library (application programming interface) for creating high quality charts. Plotly has an immensely rich collection of chart types, all of which are interactive. Another popular charting library is Matplotlib. Whereas Matplotlib only supports Python, Plotly supports Javascript, Python, as well as R. At its core, Plot.ly’s graphics are created in D3.js.

/archive-2022-2023/plotly

Chart Studio is a web-based tool that allows you to create charts and simple dashboards using Plot.ly, eliminating the need for coding skills. Additionally, charts created in Chart Studio can be exported to either Javascript or Python code, making it an excellent tool for learning and exploration.

/archive-2022-2023/plotly

Dash is a Python library for making web-based interactive visualization dashboards of Plot.ly charts. Often to create web-based dashboards you need to code the frontend in Javascript. Dash allows you to do everything in Python.

The best place to go to begin learning is Plotly’s main library page, which will then direct you to tutorials for Plotly in Python, R, Javascript, as well as Dash.

Go to the main library page and take a look at either Plotly Python or Plotly Javascript then select one of the basic charts to look at the respective codes. Also take a look at Dash example galleries.

Note: for Plotly Python there are two ways to use Plotly. I recommend most users use Plotly Express (which is a very low-code library to Plotly’s most common charts). Most of the examples you will find use Plotly Express. For advanced needs you can learn to use Plotly Graph Objects.

As an example of how easy it is to create charts in Plotly Express here are the lines of code you need to make a scatterplot:

And if you are familiar with using Pandas for data wrangling, here’s an example of a scatterplot by first reading a data file into a Pandas data frame:

And if you replaced:

with

You can get this scatterplot matrix:

/archive-2022-2023/plotly

Lastly, should you venture into creating Dash dashboards, and wish to make them publicly viewable, you will need to host a Python server. An easy way to do this is to use Pythonanywhere.

Here is a video illustrating how to do this.