Matplotlib - 折线图 plot() 所有用法详解
生活随笔
收集整理的這篇文章主要介紹了
Matplotlib - 折线图 plot() 所有用法详解
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
散點(diǎn)圖和折線圖是數(shù)據(jù)分析中最常用的兩種圖形。其中,折線圖用于分析自變量和因變量之間的趨勢(shì)關(guān)系,最適合用于顯示隨著時(shí)間而變化的連續(xù)數(shù)據(jù),同時(shí)還可以看出數(shù)量的差異,增長(zhǎng)情況。
Matplotlib 中繪制散點(diǎn)圖的函數(shù)為 plot() ,使用語(yǔ)法如下:matplotlib.pyplot.plot(*args,?scalex=True,?scaley=True,?data=None,?**kwargs)
常用參數(shù)及說(shuō)明:
?
| 參數(shù) | 接收值 | 說(shuō)明 | 默認(rèn)值 |
| x,y | array | 表示 x 軸與 y 軸對(duì)應(yīng)的數(shù)據(jù); | 無(wú) |
| color | string | 表示折線的顏色; | None |
| marker | string | 表示折線上數(shù)據(jù)點(diǎn)處的類型; | None |
| linestyle | string | 表示折線的類型; | - |
| linewidth | 數(shù)值 | 線條粗細(xì):linewidth=1.=5.=0.3 | 1 |
| alpha? | 0~1之間的小數(shù) | 表示點(diǎn)的透明度; | None |
| label | string | 數(shù)據(jù)圖例內(nèi)容:label=‘實(shí)際數(shù)據(jù)’ | None |
其他參數(shù)請(qǐng)參考文檔:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html
基本用法
import pandas as pd import matplotlib.pyplot as plt#讀取數(shù)據(jù) datafile = u'D:\\pythondata\\learn\\matplotlib.xlsx' data = pd.read_excel(datafile)plt.figure(figsize=(10,5))#設(shè)置畫(huà)布的尺寸 plt.title('Examples of line chart',fontsize=20)#標(biāo)題,并設(shè)定字號(hào)大小 plt.xlabel(u'x-year',fontsize=14)#設(shè)置x軸,并設(shè)定字號(hào)大小 plt.ylabel(u'y-income',fontsize=14)#設(shè)置y軸,并設(shè)定字號(hào)大小#color:顏色,linewidth:線寬,linestyle:線條類型,label:圖例,marker:數(shù)據(jù)點(diǎn)的類型 plt.plot(data['時(shí)間'],data['收入_Jay'],color="deeppink",linewidth=2,linestyle=':',label='Jay income', marker='o') plt.plot(data['時(shí)間'],data['收入_JJ'],color="darkblue",linewidth=1,linestyle='--',label='JJ income', marker='+') plt.plot(data['時(shí)間'],data['收入_Jolin'],color="goldenrod",linewidth=1.5,linestyle='-',label='Jolon income', marker='*')plt.legend(loc=2)#圖例展示位置,數(shù)字代表第幾象限 plt.show()#顯示圖像?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Matplotlib - 折线图 plot() 所有用法详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python网站攻击脚本_Python
- 下一篇: 数据离散化 - 等宽等频聚类离散 - P