用第一個程式可以畫出長條、橫條和堆疊,但折線圖的話會全部擠在y軸上。雖然照Pandas這網站修改後可以畫出折線圖,還是想請問為什麼第一個程式會畫不出來@@
df=pd.DataFrame([[250,320,300,312,280],
[280,300,280,290,310],
[120,280,250,305,250]],
index=["北部","中部","南部"],
columns=["2016","2017","2018","2019","2020"])
g1=df.iloc[0].plot(kind="line",xticks=range(2015,2020),title="汽車銷售量",figsize=[10,5])
g1=df.iloc[1].plot(kind="line",xticks=range(2015,2020),title="汽車銷售量",figsize=[10,5])
g1=df.iloc[2].plot(kind="line",xticks=range(2015,2020),title="汽車銷售量",figsize=[10,5])
df_1=pd.DataFrame({"北部":[250,320,300,312,280],
"中部":[280,300,280,290,310],
"南部":[120,280,250,305,250]},
index=["2016","2017","2018","2019","2020"])
print(df_1)
test=df_1.plot(kind="line",title="汽車銷售量",figsize=[10,5])
原xticks=range(2015,2020)改成xticks=range(1,5)
即可
df.iloc[0].plot(kind="line",xticks=range(1,5),title="Car sales",figsize=[10,5])
完整示範如下