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常用的模組內建常數; __name__ ; __file__ ; __doc__ ; __all__ ;__dict__; vars()->Dict[str,str] ; dir()->List[str] Python常用的模組內建常數; __name__ ; __file__ ; __doc__ ; __all__ ;__dict__; vars()->Dict[str,str] ; dir()->List[str]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221112184006_50.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Excel TQC考題202: 快樂小學學生名冊,自訂格式:0″公斤”;[紅色]”減”0″公斤”;[藍色]”完美身材” Excel TQC考題202: 快樂小學學生名冊,自訂格式:0″公斤”;[紅色]”減”0″公斤”;[藍色]”完美身材”](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/04/20220410142405_70.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: matplotlib繪圖,如何限定座標軸範圍? plt.axis([xmin, xmax, ymin, ymax]) Python: matplotlib繪圖,如何限定座標軸範圍? plt.axis([xmin, xmax, ymin, ymax])](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/02/20230208101745_93.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2023/06/20230626093403_49.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言