使用主題自訂

Julia 資料視覺化入門

Gustavo Vieira Suñe

Data Analyst

Plots.jl 主題

  • 輕鬆自訂
using Plots

# Set theme
theme(thm::Symbol; kwargs...)
  • 多種主題(thm)可選::default:dark:ggplot2:juno⋯⋯
  • kwargs:設定預設屬性

例如,theme(:juno, linecolor=:red, linewidth=5)

Julia 資料視覺化入門

主題預覽

showtheme(:ggplot2)

使用 ggplot2 主題建立的多種圖形。

showtheme(:juno)

使用 juno 主題建立的多種圖形。

Julia 資料視覺化入門

最愛音樂類型

  • 音樂對心理健康的資料集。
using DataFrames, CSV, Plots

# Load dataset
streaming = DataFrame(CSV.File("streaming.csv"))

# Group by genre grouped = groupby(streaming, "Fav genre") # Count genres counts = combine(grouped, nrow => :count)
  • 用長條圖視覺化!
Julia 資料視覺化入門

預設主題長條圖

# Bar chart with :default
bar(
    counts[!, "Fav genre"],
    counts.count,

title="Favorite Music Genres" ylabel="Frequency", label=false, )

以預設主題繪製的最愛類型計數長條圖。

Julia 資料視覺化入門

換個主題試試

# Set the theme
theme(:juno)

# Bar chart with :juno bar( counts[!, "Fav genre"], counts.count, label=false, ylabel="Frequency", title="Favorite Music Genres" )

以 juno 主題繪製的最愛類型計數長條圖。

Julia 資料視覺化入門

讓圖更醒目!

theme(
    :juno,

# Default line color and width linecolor=:red, linewidth=5,
# Hide the axis lines framestyle=:grid )
bar( counts[!, "Fav genre"], counts.count, label=false, ylabel="Frequency", title="Favorite Music Genres" )

以預設主題繪製、長條外框為粗紅線的最愛類型計數長條圖。

  • 存成檔案:savefig("genres.png")
Julia 資料視覺化入門

一起來練習吧!

Julia 資料視覺化入門

Preparing Video For Download...