Python 繪制可視化折線圖
1. 用 Numpy ndarray 作為數(shù)據(jù)傳入 ply
import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt np.random.seed(1000) y = np.random.standard_normal(10) print "y = %s"% y x = range(len(y)) print "x=%s"% x plt.plot(y) plt.show()
2. 操縱坐標(biāo)軸和增加網(wǎng)格及標(biāo)簽的函數(shù)
import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt np.random.seed(1000) y = np.random.standard_normal(10) plt.plot(y.cumsum()) plt.grid(True) ##增加格點 plt.axis('tight') # 坐標(biāo)軸適應(yīng)數(shù)據(jù)量 axis 設(shè)置坐標(biāo)軸 plt.show()
3. plt.xlim 和 plt.ylim 設(shè)置每個坐標(biāo)軸的最小值和最大值
#!/etc/bin/python #coding=utf-8 import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt np.random.seed(1000) y = np.random.standard_normal(20) plt.plot(y.cumsum()) plt.grid(True) ##增加格點 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 離散點, 線
#!/etc/bin/python #coding=utf-8 import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt np.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') #離散的點 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)注腳本之家其它相關(guān)文章!
相關(guān)文章
python“靜態(tài)”變量、實例變量與本地變量的聲明示例
這篇文章主要給大家介紹了關(guān)于python“靜態(tài)”變量、實例變量與本地變量的聲明的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11以視頻爬取實例講解Python爬蟲神器Beautiful Soup用法
這篇文章主要以視頻爬取實例來講解Python爬蟲神器Beautiful Soup的用法,Beautiful Soup是一個為Python獲取數(shù)據(jù)而設(shè)計的包,簡潔而強(qiáng)大,需要的朋友可以參考下2016-01-01python使用 HTMLTestRunner.py生成測試報告
這篇文章主要介紹了python使用 HTMLTestRunner.py生成測試報告 ,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10Python替換NumPy數(shù)組中大于某個值的所有元素實例
這篇文章主要介紹了Python替換NumPy數(shù)組中大于某個值的所有元素實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06