This is the coding component of the Data Visualization with Plotly for Python workshop.\ Please find the workshop slides here

Getting Started

Workshop Best Practices

If you have not installed plotly yet, run the following:

Task 0: Importing Libraries

image.png

  1. The plotly.express module is the recommended entry point, for it is a higher-level module compared to plotly.graph_objects.
  1. To preview the dataset, we will be trying out using the DataFrame.head() function from Pandas vs the create_table function from plotly.figure_factory, which is a graphing module that has even more unique chart types yet included in plotly.js.

Task 1: Loading Data

The data we are using today is the built-in demo data of Plotly.express module.\ The demo data is from Gapminder, detailing the life expectancy, population, GDP change every five years from 1952 to 2007.\ As you may know, in a data science life cycle, up to 80% of the time may be devoted to cleaning and processing data. The demo data we are using today has been cleaned and is ready for use.\ The main goal of today is to explore the different functionalities of the Plotly library, and this cleaned data will serve our purpose well.

Let's preview our data.

  1. Using our old friend, Pandas.
  1. Using plotly.figure_factory (also known as "ff" by abbreviation) module.

Task 2: Visualize Population Change with Bar Chart

Next, let's add some more functionalities to our graph

Task 3: Visualize GDP and Life Expectancy Data with Scatter Plot

Task 4: Customize Interactive Bubble Charts according to Population Size

Full documentation on Scatter Plot in plotly.express, which has size_max info.

Task 5: Create Facet Plots by Continent

Facet charts can be used to split a multi-trace data visualization into a matrix of data panels.\ In Plotly.express, if you want to facet a larger plot into multiple smaller plots, you simply pass in the variable you want to facet by into an attribute called "facet_col".

Interpretation Challenge: What insights can you gain from this graph?

Write it here:

Task 6: Add Animation to Facet Plots

Let's create animation so that the we can observe the yearly change of GDP VS Life Expectancy data. Code the following:

Task 7: Represent Geographic Data as Animated Maps

Choropleths are thematic maps in which areas are shaded/ patterned in proportion to the measurement of the displayed statistical variable.\ We are going to shade our maps by lifeExp using our entire dataset.

What is "locations" ='iso_alpha'?

Task 8: Line Plots VS Area Plots

Got Questions?\ Ask the Data Services Team at NYU Shanghai Library (shanghai.library@nyu.edu)

Ending Credits\ Tutorial framework: Plotly for Python documentation\ Reference: Kaggle\ Modified and Organized by: Pamela Pan (pp1813@nyu.edu)