Data Science Applications to Astronomy
Week 10: Data Visualization:
Making Effective Figures
General Presentation Tips
What is the purpose of your presentation/slide/figure?
What is essential to accomplishing that goal?
What content is only periperial?
Who is your audience?
What do they...
Already know well?
Have already heard, but need a reminder?
Not know, but are well-prepared to understand?
Not know and need scaffolding to appreciate?
Choose complexity of figure (or entire presentation) to your audience.
Example: Color-luminosity diagram of stars in local neighborhood
–- Credit: Gaia Collaboration (2018) (DR2) & Vlas Sokolov
Figures
Choose what variables to plot
Can you choose a set of variables that:
Shows what is most directly observable
Makes the relationship simpler or more obvious
Makes the figure more general ("switch to theorist units")
Makes the figure easier to compare to observations ("switch to observer units")
Would a transformation make the relationship (nearly) linear?
Log
Power-law
Divide by a baseline model
Example: Transit timiing variations
Most directly observable: Transit times vs Time
Makes the relationship more obvious: Residual of Transit time minus linear transit timing model
Observer units
X-axis: Transit times (\(t_n\)'s) in days or years
Y-axis: Residuals (\(\Delta~t_n\)'s) in minutes
Theorist units
X-axis: Transit Number (\(n\)'s)
Y-axis: Residuals (\(\Delta~t_n\)'s) in fraction of orbital period
Figure type
Start with figure type that's well-suited for the data and purpose of the plot.
Points – measurements
Lines – predictions of models
Contours or Heatmap – 2-d histogram or probability density
Bar chart – comparing categorical data
Vector field or quiver – velocities in fluid flow
Box plot or Violin plots – comparing distributions"
Example: Quiver Plot
Example: Violin Plot
Fonts
Use font large enough to read
Sans serif is easier to read (especially if small)
Font includes accents or symbols to be used
Choose colors wisely
Proportional spacing vs
Mono-spaced
Example of mathematical symbols
| Row | Glyph | LaTeX | Description |
|---|---|---|---|
| String | String | String | |
| 1 | ɸ | \\ltphi | Latin Small Letter Phi |
| 2 | φ | \\varphi | Greek Small Letter Phi |
| 3 | ϕ | \\phi | Greek Phi Symbol / Greek Small Letter Script Phi |
| 4 | ᵠ | \\^phi | Modifier Letter Small Greek Phi |
| 5 | ᵩ | \\_phi | Greek Subscript Small Letter Phi |
| 6 | 𝛗 | \\bfvarphi | Mathematical Bold Small Phi |
| 7 | 𝛟 | \\bfphi | Mathematical Bold Phi Symbol |
| 8 | 𝜑 | \\itphi | Mathematical Italic Small Phi |
| 9 | 𝜙 | \\itvarphi | Mathematical Italic Phi Symbol |
| 10 | 𝝋 | \\biphi | Mathematical Bold Italic Small Phi |
| 11 | 𝝓 | \\bivarphi | Mathematical Bold Italic Phi Symbol |
| 12 | 𝞅 | \\bsansphi | Mathematical Sans-Serif Bold Small Phi |
| 13 | 𝞍 | \\bsansvarphi | Mathematical Sans-Serif Bold Phi Symbol |
| 14 | 𝞿 | \\bisansphi | Mathematical Sans-Serif Bold Italic Small Phi |
| 15 | 𝟇 | \\bisansvarphi | Mathematical Sans-Serif Bold Italic Phi Symbol |
JuliaMono has great coverage.
Axes
Label axes
Specify units (unless dimensionless)
≥ 3 tick marks per axis
Plenty of space between axis labels
Axis Range
Don't just accept default axis scales!
Scale that includes all points may hide important variations.
Zooming in all the way can give the impression that variations are large, regardless of whether they are small or large.
Questions to ask:
Does zero (or one) have significance?
Linear vs Log?
Would showing residuals to a baseline model be more helpful (or just more confusing)?
Show erorrbars?
Lines
Increase line width (or weight) when used for print or projection
Hard to tell apart more than 4 line styles
Distinguish lines with both color and line style
Points
Increase point size, especially for print or projection
Hard to tell apart more than ~5 point (marker) shapes
Too many points overlapping can be misleading
Convey measurement uncertainties
let
plt = plot( xlabel="X", ylabel="Y", color_palette=ColorScheme(cvd_dict[cvd].(ColorSchemes.Paired_12)), legend=:none)
x = 0:0.1:2π
y = sin.(x)
lw = 4
shape_wo_stroke = [:circle, :rect, :star5, :diamond, :hexagon, :utriangle, :dtriangle, :rtriangle, :ltriangle, :pentagon, :heptagon, :octagon, :star4, :star6, :star7, :star8]
shape_w_stroke = [:cross, :xcross, :vline, :hline]
for i in 1:length(shape_wo_stroke)
scatter!(plt, x, y.+i.*0.1, markershape=shape_wo_stroke[i], markersize=3.5, markerstrokewidth=0)
end
for i in 1:length(shape_w_stroke)
j = i + length(shape_wo_stroke)
scatter!(plt, x, y.+j.*0.1, markershape=shape_w_stroke[i], markersize=3.5, markerstrokewidth=3)
end
plt
end
Contours:
Point size:
Colors
Why are you using color?
1. To convey additional information
2. Draw attention to one element
begin # Microlensing magnification for single lens
A(u) = (2+u^2)/(u*sqrt(4+u^2))
u(t; u0::Real, t0::Real=zero(t), tE::Real=one(t) ) = sqrt(u0^2+(t-t0)^2/tE^2)
end;
begin
plt_accent = plot(xlabel = "Time", ylabel="Magnification", legend=:none)
local t = -5:0.02:5
local flux = 0.5 .*( A.(u.(t,u0=0.75)) .+ A.(u.(t,u0=2,t0=2,tE=0.05)) )
flux .+= 0.005.*randn(length(flux))
scatter!(plt_accent, t, flux, markersize=2, markerstrokewidth=0 )
local idx_accent = findall(t->abs(t-2)<0.15, t)
scatter!(plt_accent, t[idx_accent], flux[idx_accent], markersize=2, markerstrokewidth=0 )
end
#$plt_accent
md"""
#### 3. To fit in with color palette
$cs_ex_psu_penn
"""
3. To fit in with color palette
Choosing a Color Palette
Continuous Values
Should it be perceptually uniform?
Otherwise can give an inaccurate impression
What if you print it in black & white?
Is there sufficient contrast?
Especially important when using projector
Can truncate palette to avoid using too light a color
How is perceived by people with a color vision deficiency?
Examples:
Linear (e.g.,
lajolla)
vs vs
Diverging (e.g.,
vik)
vs
Cyclic (e.g.,
cyclic_protanopic_deuteranopic_bwyk_16_96_c31_n256)
vs
Color Vision Deficiency:
Categories
Unordered
Ordered Categories
Paired
Other common mistakes
Cramming too much information into a figure
The goal of visualization is to make it easy for the audience to understand, and not to show off your skill at making complicated plots.
When giving a presentation, can build up a figure step-by-step to turn complex figure into a story.
Making plot 3d when 2d would be easier to interpret
Using yellows in a presentation to be displayed with a projector
Keep your eyes open for...
Particularly effective plots
Poorly executed plots
Plot that are complex, but still readable thanks to good design
Think about why they were good/bad and what you can learn from it.
Setup & Helper Code
begin
using PlutoUI, PlutoTeachingTools
using Plots, Plots.PlotMeasures, LaTeXStrings
using StatsPlots, KernelDensity
using Colors, ColorSchemes, FixedPointNumbers
using DataFrames
end
Figures
PSU Palletes
Color vision deficiency code
Built with Julia 1.11.5 and
ColorSchemes 3.29.0Colors 0.12.11
DataFrames 1.4.4
FixedPointNumbers 0.8.5
KernelDensity 0.6.9
LaTeXStrings 1.3.1
Plots 1.35.8
PlutoTeachingTools 0.2.15
PlutoUI 0.7.61
StatsPlots 0.15.7
To run this tutorial locally, download this file and open it with Pluto.jl.