1 of 40

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

data6.org/su25/syllabus/#acknowledgements-

2 of 40

Week 6

Announcements!

  • Week 5 Survey has been released and will be due 8/14 @ 11 PM
  • Final Project will be due 8/16 @ 11 PM
  • Lectures this week will only be from �10-11 AM
  • Utilize Office Hours in the run-up to the final exam on 8/15
    • Jedi’s OH changes to Tues-Fri, �8-10 PM on Zoom
  • Final Exam is on Friday 10-12 PM @ SOCS 170
    • Two pages for cheat sheet (8.5 x 11 inches, front and back)
  • Fill out course evaluations!
  • No tutoring this week

2

3 of 40

Icebreaker

What superpower would you pick (be creative)?

3

4 of 40

Today’s Roadmap

Lecture 30, Data 6 Summer 2025

  1. Review of Visualization
  2. New Visualization Techniques
  3. A Note on Perception

4

5 of 40

Visualizations So Far

5

1. Visualizations So Far

2. New Visualization Techniques

3. Demo

6 of 40

6

7 of 40

Bar Charts

Bar charts are often used to display the relationship between a categorical variable and a numerical variable:

  • Average GPAs of Data Science, History, and Biology majors.
  • The number of streams by the top 10 songs on Spotify yesterday.

7

8 of 40

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.

  • It automatically chooses bins for us. We can change them.
  • We will almost always set density = False.

8

9 of 40

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:

  • group (str): points will be colored according to category in this categorical column.
  • labels (str): points will be labeled according to their value in this column.

10 of 40

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.

  • column_for_x should contain some time-based variable.
  • If only column_for_x is provided, a separate line plot is drawn for every other column in t (similar to the behavior of barh and scatter).

11 of 40

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.

  • Scatter plots with geographic maps
  • Help you visualize geographic locations in relation to cities, states, and countries.

11

Scatters Plot + Map = ❤️

Use px.scatter_geo(df, lat, lon)

data frame, latitude, longitude

12 of 40

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

13 of 40

New Visualization Techniques

13

1. Visualizations So Far

2. New Visualization Techniques

3. Demo

14 of 40

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.

  • Plotly can be quite confusing and difficult to understand
  • The documentation is really helpful

We do not expect you to memorize/remember any Plotly syntax. This is purely for fun.

14

15 of 40

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

16 of 40

Hans Rosling (1948-2017)

16

17 of 40

Updated Gapminder

17

18 of 40

Animated Scatter Plots

18

19 of 40

Animated Histograms

19

20 of 40

Box Plots

20

21 of 40

Box Plots: Which Do You Prefer?

21

From @CedScherer on Twitter

22 of 40

Pie Charts

22

23 of 40

Timelines (Gantt Charts)

23

24 of 40

Choropleths Maps (Review)

24

25 of 40

Animated Choropleth Maps

25

26 of 40

3D Scatter Plots

26

27 of 40

Which Is Better?

27

28 of 40

Questions?

28

29 of 40

A Note on Perception

29

1. Visualizations So Far

2. New Visualization Techniques

3. A Note on Perception

30 of 40

How much longer is the top bar?

31 of 40

The top bar is 7 times longer than the bottom bar.

32 of 40

How much bigger is the big circle?

33 of 40

The area of the big circle is 7 times larger than the area of the small circle.

34 of 40

Which is easier to understand?

35 of 40

Question: In which one of these two graphs is it easier to compare cities?

Answer: The bar chart.

36 of 40

Perception

As humans, we perceive changes in different encodings differently.

  • It’s easier to tell if one bar is 10% longer than another than to tell if one circle is 10% larger than the other.

This hierarchy is for comparing continuous variables, and explains why we prefer bar charts to pie charts.

  • It doesn’t mean we should never use colors, though – they’re needed to separate categories or to denote values in maps.

37 of 40

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.

  • Tufte claims that chart junk should be avoided at all costs as it increases cognitive load.
  • Others claim that interesting additions to visualizations can make them more memorable.

What do you think?

38 of 40

In Conclusion…

38

39 of 40

Summary

  • Plotly is a very powerful mapping/visualization library, but you’re not expected to be an expert at it
    • Leverage Plotly’s powerful features to create engaging and insightful visualizations
  • But remember, just because you can do something doesn’t mean you should

39

Plot (wise)ly!

40 of 40

Recap

Next Time

40

  • Review of Visualization So Far
    • Bar Charts and Histograms
    • Scatter Plots and Line Plots
    • Scatter Plot Maps and Choropleth Maps
  • New Visualization Techniques
  • Perception
    • Chart Junk
  • Review for Final