iT邦幫忙

2021 iThome 鐵人賽

DAY 24
0
AI & Data

使用python學習Machine Learning系列 第 24

Day 24 [Python ML、資料視覺化] 如何選擇圖表型態

你學到了甚麼?

我們可以將學到的圖表分為3類

  • Trends - 可以定義一種變換的模式
    • sns.lineplot - Line Charts可以顯示時間和數據間的趨勢
  • Relationship - 有很多不同的圖表類型可以了解不同變數之間的關係
    • sns.barplot - Bar charts是可以比較不同column之間的數量
    • sns.heatmap - Heatmaps可以將數據中的資料做顏色編碼
    • sns.scatterplot - Scatter plots可以顯示兩個連續資料之間的關係,若加上顏色,則可以顯示類別數據
    • sns.regplot - 在scatter plot中加上回歸線,可以更清楚的資料兩個資料間的關係
    • sns.lmplot - 可以再scatter plot中加上多個回歸線
    • sns.swarmplot - Categorical scatter plots顯示連續資料及類別資料之間的關係
  • Distribution - 可以統計某一個資料中的數據量,並將其視覺化
    • sns.displot - Histograms顯示單一數值變數的分布
    • sns.kdeplot - ** KDE plots(or 2D KDE plots)**將質方圖變得更緩和
    • sns.jointplot - 將兩個直方圖結合

Changing styles with seaborn

import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
print("Setup Complete")
Setup Complete
# Path of the file to read
spotify_filepath = "./spotify.csv"

# Read the file into a variable spotify_data
spotify_data = pd.read_csv(spotify_filepath, index_col="Date", parse_dates=True)

# Line chart 
plt.figure(figsize=(12,6))
sns.lineplot(data=spotify_data)
<AxesSubplot:xlabel='Date'>

可以加上顏色讓圖表看起來比較不一樣

# Change the style of the figure to the "dark" theme
sns.set_style("dark")

# Line chart 
plt.figure(figsize=(12,6))
sns.lineplot(data=spotify_data)
<AxesSubplot:xlabel='Date'>


上一篇
Day 23 [Python ML、資料視覺化] 直方圖、密度圖
下一篇
Day 25 [Python ML、資料清理] 處理遺失值
系列文
使用python學習Machine Learning29
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言