import matplotlib.pyplot as plt
import pandas as pd
# 示例数据
x = [1, 2, 3, 4, 5]
y = pd.DataFrame({
'Data1': [2, 4, 6, 8, 10],
'Data2': [3, 6, 9, 12, 15],
'Data3': [1, 3, 5, 7, 9]
})
# 绘制图形
fig, ax = plt.subplots()
lines = ax.plot(x, y)
labels = y.columns.tolist()
ax.legend(lines, labels)
plt.show()輸出結果:

lines = ax.plot(x, y)

df = pd.DataFrame(y, index=x)
y的原index= 0~4
要改為x (1~5)
沒有完全match
原本index = 0的那一row被刪除了
多了index = 5的那一row,內容為NaN

ax=df.plot()

自動加上欄標籤當legend
y.index=x
這方法才不會刪除
index不match的row 資料

推薦hahow線上學習python: https://igrape.net/30afN
![Python socket連線出現[WinError 10049] 內容中所要求的位址不正確 cmd.exe: ipconfig/all ; TCP/IPv4 vs IPv6 Python socket連線出現[WinError 10049] 內容中所要求的位址不正確 cmd.exe: ipconfig/all ; TCP/IPv4 vs IPv6](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/10/20221028151556_42.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: 自定義函數計算計程車車資(先typing,再用預設值), 巢狀字典以及typing.Union[ ], assert 斷言 Python: 自定義函數計算計程車車資(先typing,再用預設值), 巢狀字典以及typing.Union[ ], assert 斷言](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220923222039_57.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220907154601_86.png?quality=90&zoom=2&ssl=1&resize=350%2C233)





近期留言