1. 程式人生 > 程式設計 >Matplotlib 折線圖plot()所有用法詳解

Matplotlib 折線圖plot()所有用法詳解

散點圖和折線圖是資料分析中最常用的兩種圖形。其中,折線圖用於分析自變數和因變數之間的趨勢關係,最適合用於顯示隨著時間而變化的連續資料,同時還可以看出數量的差異,增長情況。

Matplotlib 中繪製散點圖的函式為 plot() ,使用語法如下:matplotlib.pyplot.plot(*args,scalex=True,scaley=True,data=None,**kwargs)

常用引數及說明:

引數 接收值 說明 預設值
x,y array 表示 x 軸與 y 軸對應的資料;
color string 表示折線的顏色; None
marker string 表示折線上資料點處的型別; None
linestyle string 表示折線的型別; -
linewidth 數值 線條粗細:linewidth=1.=5.=0.3 1
alpha 0~1之間的小數 表示點的透明度; None
label string 資料圖例內容:label=‘實際資料' None

其他引數請參考文件:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html

基本用法

import pandas as pd
import matplotlib.pyplot as plt
 
#讀取資料
datafile = u'D:\\pythondata\\learn\\matplotlib.xlsx'
data = pd.read_excel(datafile)
 
plt.figure(figsize=(10,5))#設定畫布的尺寸
plt.title('Examples of line chart',fontsize=20)#標題,並設定字號大小
plt.xlabel(u'x-year',fontsize=14)#設定x軸,並設定字號大小
plt.ylabel(u'y-income',fontsize=14)#設定y軸,並設定字號大小
 
#color:顏色,linewidth:線寬,linestyle:線條型別,label:圖例,marker:資料點的型別
plt.plot(data['時間'],data['收入_Jay'],color="deeppink",linewidth=2,linestyle=':',label='Jay income',marker='o')
plt.plot(data['時間'],data['收入_JJ'],color="darkblue",linewidth=1,linestyle='--',label='JJ income',marker='+')
plt.plot(data['時間'],data['收入_Jolin'],color="goldenrod",linewidth=1.5,linestyle='-',label='Jolon income',marker='*')
 
plt.legend(loc=2)#圖例展示位置,數字代表第幾象限
plt.show()#顯示影象

Matplotlib 折線圖plot()所有用法詳解

到此這篇關於Matplotlib 折線圖plot()所有用法詳解的文章就介紹到這了,更多相關Matplotlib 折線圖plot()用法內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!