4. Creating Visualizations with Code

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.

/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, we will use enrollment data from across the UH System. Here are the lines of code you need to first make a barplot. Starting with importing relevant libraries:

And here we use Pandas for data wrangling:

Next, we use plotly express to create a bar plot:

/plotly

We can then look at the enrollment across two institutions through time:

/plotly

We can also investigate enrollment by Hawaiian legacy with a pie chart:

/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.