Plot Attributes and Color Palettes

Introduction to Data Visualization with Julia

Gustavo Vieira Suñe

Data Analyst

Color palettes

  • Many color palettes, including

A figure previewing different Julia color palettes.

1 https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/
Introduction to Data Visualization with Julia

Using palettes

# Set the theme
theme(:bright)


# Create a scatter plot scatter( streaming.Age, streaming."Frequency [K pop]", group=streaming."Frequency [K pop]", label=false,
# Set color palette palette=:Dark2_5 )
xlabel!("Age") ylabel!("Frequency of Play")

A scatter plot depicting the frequency of respondents' K-Pop listening habits against their age.

Introduction to Data Visualization with Julia

Plot attributes

Previously encountered:

  • title, xlabel, ylabel
  • xticks, yticks
  • color
  • linecolor, linewidth
  • markercolor
  • framestyle

Many more:

  • xlims, ylims
  • alpha
  • linestyle
  • legend_title, legend_position
  • markersize, markershape

...

1 https://docs.juliaplots.org/stable/attributes/#attributes
Introduction to Data Visualization with Julia

Marker attributes

theme(:bright)

scatter(
    streaming.Age,
    streaming."Frequency [K pop]",
    group=streaming."Frequency [K pop]",
    label=false,
    palette=:Dark2_5

# Marker attributes markershape=:diamond, markersize=8, )
xlabel!("Age") ylabel!("Frequency of Play")

A scatter plot depicting the frequency of respondents' K-Pop listening habits against their age, with large diamond-shaped markers.

Introduction to Data Visualization with Julia

Opacity/Transparency

theme(:bright)

scatter(
    streaming.Age,
    streaming."Frequency [K pop]",
    group=streaming."Frequency [K pop]",
    label=false,
    palette=:Dark2_5
    markershape=:diamond,
    markersize=8,

# Opacity alpha=0.25 )
xlabel!("Age") ylabel!("Frequency of Play")

A scatter plot depicting the frequency of respondents' K-Pop listening habits against their age, with large diamond-shaped markers with some transparency.

Introduction to Data Visualization with Julia

Line attributes

# Set theme and default line width
theme(:dao, linewidth=4)

# Create histogram histogram(streaming.BPM, label="Observed", color=:lightslateblue, normalize=true)
# Add density plot density!(streaming.BPM, label="Distribution", linecolor=:green2,
# Line style linestyle=:dash)
xlabel!("BPM") ylabel!("Probability")

A normalized histogram depicting the preferred beats per minute of the survey respondents with a density plot added to visualize the estimated distribution.

Introduction to Data Visualization with Julia

Axis bounds and legend attributes

theme(:dao, linewidth=4)

histogram(streaming.BPM, label="Observed", 
    color=:lightslateblue, normalize=true)
density!(streaming.BPM, label="Distribution",
    linecolor=:green2, linestyle=:dash

# Customize legend legend_title="Type", legend_position=:topright)
# Set the x-axis bounds xlims!(50, 230)
xlabel!("BPM") ylabel!("Probability")

A normalized histogram depicting the preferred beats per minute of the survey respondents with a density plot added to visualize the estimated distribution.

Introduction to Data Visualization with Julia

Cheat sheet

  • Color palettes
    • plot(..., palette=palette_symbol)
  • Marker attributes
    • markersize
    • markershape

A figure previewing marker shapes available in Plots.jl.

  • Opacity: alpha=opacity_value
  • Axis bounds: xlims!(), ylims!()
  • Line attribute: linetyle A figure previewing line styles available in Plots.jl.

  • Legend attributes

    • legend_title
    • legend_position (:right, :left, :top, :bottom, :topright, :topleft, ...)
Introduction to Data Visualization with Julia

Let's practice!

Introduction to Data Visualization with Julia

Preparing Video For Download...