Fun with Plotly
1
Data 6 Summer 2025
LECTURE 30
More cool tools to add to our visualization toolkit.
Developed by students and faculty at UC Berkeley and Tuskegee University
Week 6
Announcements!
2
Icebreaker
What superpower would you pick (be creative)?
3
Today’s Roadmap
Lecture 30, Data 6 Summer 2025
4
Visualizations So Far
5
1. Visualizations So Far
2. New Visualization Techniques
3. Demo
➤
6
Bar Charts
Bar charts are often used to display the relationship between a categorical variable and a numerical variable:
7
Histograms
A histogram visualizes the distribution of a numerical variable by binning. The method
t.hist(column, density = False)
creates a histogram of the column column of t. This column must contain numerical values.
8
Scatter Plots
9
The method
t.scatter(column_for_x, column_for_y)
creates a scatter plot using the specified columns. Both columns must contain numerical values.
Optional arguments, in addition to color column_for_x, column_for_y:
Line Plots
The method
t.plot(column_for_x, column_for_y)
creates a line plot using the specified columns. Both columns must contain numerical values.
Scatter Plot Maps
When we want to visualize the geographic locations of a lot of data points, it's often helpful to start with a scatter plot map.
11
Scatters Plot + Map = ❤️
Use px.scatter_geo(df, lat, lon)
data frame, latitude, longitude
Choropleth Maps
Choropleth maps are useful for visualizing numerical variables across different states or countries. In this sense, they are analogous to bar charts, since they encode one categorical variable (state or country) and one numerical variable.
12
Aggregation!
Use px.choropleth(df, locations)
data frame, state abbreviations
New Visualization Techniques
13
1. Visualizations So Far
2. New Visualization Techniques
3. Demo
➤
We Love Plotly ❤️
Plotly
For our visualizations we will use a Python library called Plotly (px in your notebooks). Plotly is a commonly used visualization library and is really useful for creating maps.
We do not expect you to memorize/remember any Plotly syntax. This is purely for fun.
14
Gapminder Dataset
Our data today comes from the Gapminder Foundation, a non-profit organization “that promotes sustainable global development and achievement of the United Nations Millennium Development Goals by increased use and understanding of statistics” (Wikipedia)
15
Hans Rosling (1948-2017)
16
Updated Gapminder
17
Animated Scatter Plots
18
Animated Histograms
19
Box Plots
20
Box Plots: Which Do You Prefer?
21
From @CedScherer on Twitter
Pie Charts
22
Timelines (Gantt Charts)
23
Choropleths Maps (Review)
24
Animated Choropleth Maps
25
3D Scatter Plots
26
Which Is Better?
27
Questions?
28
A Note on Perception
29
1. Visualizations So Far
2. New Visualization Techniques
3. A Note on Perception
➤
How much longer is the top bar?
The top bar is 7 times longer than the bottom bar.
How much bigger is the big circle?
The area of the big circle is 7 times larger than the area of the small circle.
Which is easier to understand?
Question: In which one of these two graphs is it easier to compare cities?
Answer: The bar chart.
Perception
As humans, we perceive changes in different encodings differently.
This hierarchy is for comparing continuous variables, and explains why we prefer bar charts to pie charts.
Related: Chart Junk
“Chart junk”, a term pioneered by Edward Tufte, refers to the elements of a visualization that are not strictly necessary to convey the data.
What do you think?
In Conclusion…
38
Summary
39
Plot (wise)ly!
Recap
Next Time
40