Python 繪制可視化折線圖
1. 用 Numpy ndarray 作為數(shù)據(jù)傳入 ply
import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltnp.random.seed(1000)y = np.random.standard_normal(10)print 'y = %s'% yx = range(len(y))print 'x=%s'% xplt.plot(y)plt.show()
2. 操縱坐標(biāo)軸和增加網(wǎng)格及標(biāo)簽的函數(shù)
import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltnp.random.seed(1000)y = np.random.standard_normal(10)plt.plot(y.cumsum())plt.grid(True) ##增加格點(diǎn)plt.axis(’tight’) # 坐標(biāo)軸適應(yīng)數(shù)據(jù)量 axis 設(shè)置坐標(biāo)軸plt.show()
3. plt.xlim 和 plt.ylim 設(shè)置每個(gè)坐標(biāo)軸的最小值和最大值
#!/etc/bin/python#coding=utf-8import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltnp.random.seed(1000)y = np.random.standard_normal(20)plt.plot(y.cumsum())plt.grid(True) ##增加格點(diǎn)plt.xlim(-1,20)plt.ylim(np.min(y.cumsum())- 1, np.max(y.cumsum()) + 1)plt.show()
4. 添加標(biāo)題和標(biāo)簽 plt.title, plt.xlabe, plt.ylabel 離散點(diǎn), 線
#!/etc/bin/python#coding=utf-8import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltnp.random.seed(1000)y = np.random.standard_normal(20)plt.figure(figsize=(7,4)) #畫布大小plt.plot(y.cumsum(),’b’,lw = 1.5) # 藍(lán)色的線plt.plot(y.cumsum(),’ro’) #離散的點(diǎn)plt.grid(True)plt.axis(’tight’)plt.xlabel(’index’)plt.ylabel(’value’)plt.title(’A simple Plot’)plt.show()
以上就是Python 繪制可視化折線圖的詳細(xì)內(nèi)容,更多關(guān)于Python 繪制折線圖的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. XML入門的常見問題(一)2. html小技巧之td,div標(biāo)簽里內(nèi)容不換行3. PHP字符串前后字符或空格刪除方法介紹4. jsp cookie+session實(shí)現(xiàn)簡易自動(dòng)登錄5. jsp實(shí)現(xiàn)登錄界面6. css進(jìn)階學(xué)習(xí) 選擇符7. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法8. 解析原生JS getComputedStyle9. Echarts通過dataset數(shù)據(jù)集實(shí)現(xiàn)創(chuàng)建單軸散點(diǎn)圖10. AspNetCore&MassTransit Courier實(shí)現(xiàn)分布式事務(wù)的詳細(xì)過程
