視覺化分佈

Julia 資料視覺化入門

Gustavo Vieira Suñe

Data Analyst

印度喀拉拉邦的洋蔥與小麥價格

  • kerala DataFrame:
Date Centre Commodity Price
JAN-2001 Ernakulam Onion 10.0
JAN-2001 Ernakulam Wheat 12.5
JAN-2001 Khozhikode Onion 9.0
JAN-2001 Khozhikode Wheat 14.0
... ... ... ...
MAR-2021 Trivandrum Onion 45.0
MAR-2021 Trivandrum Wheat 34.0
  • 洋蔥與小麥的價格差多少?
Commodity Mean Price
Onion 25.7442
Wheat 20.6261
Julia 資料視覺化入門

用直方圖視覺化分佈

顯示洋蔥與小麥價格分佈的直方圖。

Julia 資料視覺化入門

洋蔥與小麥的價格分佈

# Plot a histogram
histogram(
    kerala[:, :Price],

# Add a label label="Onion and Wheat", # Choose bar color color=:darkseagreen1, )
# Add axis labels xlabel!("Price (Rupees)") ylabel!("Frequency")

顯示洋蔥與小麥價格分佈的直方圖。

Julia 資料視覺化入門

分箱數(bins)

# Plot a histogram
histogram(
    kerala[:, :Price],
    # Add a label
    label="Onion and Wheat",
    # Choose bar color
    color=:darkseagreen1,

# Number of bins bins=20, ) # Add axis labels xlabel!("Price (Rupees)") ylabel!("Frequency")

顯示洋蔥與小麥價格分佈、分箱數較少的直方圖。

Julia 資料視覺化入門

分箱數(bins)

# Plot a histogram
histogram(
    kerala[:, :Price],
    # Add a label
    label="Onion and Wheat",
    # Choose bar color
    color=:darkseagreen1,
    # Number of bins
    bins=range(0, 150, 75),
)
# Add axis labels
xlabel!("Price (Rupees)")
ylabel!("Frequency")

顯示洋蔥與小麥價格分佈、分箱數較多的直方圖。

Julia 資料視覺化入門

標準化直方圖

# Plot a normalized histogram
histogram(
    kerala[:, :Price],
    # Add a label
    label="Onion and Wheat",
    # Choose bar color
    color=:darkseagreen1,

# Normalize it normalize=true, ) # Add axis labels xlabel!("Price (Rupees)") ylabel!("Probability")

顯示洋蔥與小麥價格分佈的標準化直方圖。

Julia 資料視覺化入門

機率分佈

using StatsPlots

density!( kerala[:, :Price], color=:black, linewidth=3, label=false )

直方圖上疊加機率密度曲線,顯示洋蔥與小麥價格的機率分佈。

Julia 資料視覺化入門

各商品的價格

using StatsPlots

# Grouped histogram
groupedhist(
    kerala[:, :Price],

# Group by commodity group=kerala[:, "Commodity"],
# Select colors color=[:deeppink3 :wheat2] ) xlabel!("Price (Rupees)") ylabel!("Frequency")

群組直方圖,分別以並排柱狀顯示洋蔥與小麥價格。

Julia 資料視覺化入門

堆疊直方圖

using StatsPlots

# Stacked histogram
groupedhist(
    kerala[:, :Price],
    # Group by commodity
    group=kerala[:, "Commodity"],
    # Select colors
    color=[:deeppink3 :wheat2]

# Stack the bars bar_position=:stack, )
xlabel!("Price (Rupees)") ylabel!("Frequency")

群組直方圖,分別顯示洋蔥與小麥價格,並將柱狀堆疊。

Julia 資料視覺化入門

細微差異

群組直方圖,分別顯示洋蔥與小麥價格,並將柱狀堆疊。

  • 尖峰價格看起來非常相近。
Commodity Mean Price
Onion 25.7442
Wheat 20.6261
  • 洋蔥價格有長尾。
  • 中位數幾乎相同。
Commodity Median Price
Onion 20.0
Wheat 19.5
  • 平均數差異是長尾造成的!
Julia 資料視覺化入門

一起來練習吧!

Julia 資料視覺化入門

Preparing Video For Download...