import seaborn as sns
import matplotlib.pyplot as plt
# import pandas as pd
# 載入數據集
tips = sns.load_dataset(“tips”)
# tips.to_excel(r”C:\Temp\tips.xlsx”)
# 繪製圖表
g = sns.relplot(data=tips, x=”total_bill”, y=”tip”,
col=”day”, hue=”sex”, col_wrap=2)
# 設置圖表標題
g.fig.suptitle(“Tips by Day and Gender”)
“””這行程式碼是用來設定 Seaborn 繪圖物件 g 的標題,fig 是指 Seaborn 繪圖物件的 Figure 物件,suptitle 是指設定 Figure 物件的標題。因此,這行程式碼會在圖片上方中央顯示 “Tips by Day and Gender” 的標題。”””
# 顯示圖表
plt.show()

tips(DataFrame):

若將tips輸出為xlsx檔:

day共有四天
g = sns.relplot(data=tips, x=”total_bill”, y=”tip”,
col=”day”, hue=”sex”, col_wrap=2)
col_wrap=2 限制欄數最多為2
輸出的圖檔:

g = sns.relplot(data=tips, x=”total_bill”, y=”tip”,
col=”day”, hue=”sex”)
去掉col_wrap=2參數
輸出圖檔:

g = sns.relplot(data=tips, x=”total_bill”, y=”tip”,
col=”day”, hue=”sex”,col_wrap=2, kind=”line”)
多加參數 kind=”line”
換成折線圖

推薦hahow線上學習python: https://igrape.net/30afN



![一文搞懂Python pandas.DataFrame去重:df.drop_duplicates() 與 df[~df.duplicated()] 的等價、差異與最佳實踐 一文搞懂Python pandas.DataFrame去重:df.drop_duplicates() 與 df[~df.duplicated()] 的等價、差異與最佳實踐](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/08/20250808202701_0_66f9bc.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python: 字串 str.find(關鍵字[,start][,end]),找不到的話回傳-1,如何找出資料字串中,所有關鍵字的index?詞頻計算 Python: 字串 str.find(關鍵字[,start][,end]),找不到的話回傳-1,如何找出資料字串中,所有關鍵字的index?詞頻計算](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221122100657_32.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言