python繪制棉棒圖的方法詳解
更新時間:2022年03月24日 16:11:27 作者:Vergil_Zsh
這篇文章主要為大家詳細(xì)介紹了python繪制棉棒圖的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
用法:
matplotlib.pyplot.stem(*args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, label=None, use_line_collection=True, orientation='vertical', data=None)
參數(shù)說明
| 參數(shù) | |
|---|---|
| *args | x,y,x—棉棒的x軸基線的取值范圍,y—棉棒的長度 |
| linefmt | 棉棒的樣式,{‘-’,’–’,’:’,’-.’},包括指定顏色等 |
| markerfmt | 棉棒末端的樣式 |
| basefmt | 指定基線的樣式 |
| bottom | 默認(rèn)值為0,極限的y/x的位置,取決于方向 |
| label | 用于標(biāo)簽 |
| use_line_collection | 默認(rèn)值是True,如果為True,棉棒的莖線存儲并繪制為線集合,而不是單獨(dú)的線,這將顯著提高性能,而不是單獨(dú)的線 |
| orientation | 控制方向,默認(rèn)為垂直(True). |
案例
參數(shù)
x,y
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) plt.stem(x, y) plt.show()

linefmtlinefmt用來指定棉棒的顏色和樣式等
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1,2 * np.pi, 41)
y = np.exp(np.sin(x))
fit, axs = plt.subplots(nrows=2, ncols=2, figsize=(14,7))
axs[0,0].set_title("linefmt='-',color='green'")
axs[0,0] = axs[0,0].stem(x,y,linefmt='g-')
axs[0,1].set_title("linefmt='-.', color='blue'")
axs[0,1] = axs[0,1].stem(x,y,linefmt='b-.')
axs[1,0].set_title("linefmt=':', color='red'")
axs[1,0] = axs[1,0].stem(x,y,linefmt='r:')
axs[1,1].set_title("linefmt='--', color='p'")
axs[1,1] = axs[1,1].stem(x,y,linefmt='o--')
plt.show()

basefmt
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1,2 * np.pi, 41)
y = np.exp(np.sin(x))
fit, axs = plt.subplots(nrows=2, ncols=1, figsize=(14,7))
axs[0].set_title("basefmt='-',color='C2'")
axs[0] = axs[0].stem(x,y,linefmt='b--',basefmt='C2--')
axs[1].set_title("basefmt='-.', color='C1'")
axs[1] = axs[1].stem(x,y,linefmt='b-.',basefmt='C1-.')
plt.show()

bottom
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0.1,2 * np.pi, 41)
y = np.exp(np.sin(x))
fit, axs = plt.subplots(nrows=1, ncols=2, figsize=(14,7))
axs[0].set_title("bottom")
axs[0].stem(x,y,linefmt='grey',markerfmt='D',bottom=1.1)
axs[1].set_title('no bottom')
axs[1].stem(x,y,linefmt='grey',markerfmt='D')
plt.show()

案例
import numpy as np import matplotlib.pyplot as plt # 生成模擬數(shù)據(jù)集 x=np.linspace(0,10,20) y=np.random.randn(20) # 繪制棉棒圖 markerline, stemlines, baseline = plt.stem(x,y,linefmt='-',markerfmt='o',basefmt='--',label='TestStem') # 可單獨(dú)設(shè)置棉棒末端,棉棒連線以及基線的屬性 plt.setp(markerline, color='k')#將棉棒末端設(shè)置為黑色 plt.legend() plt.show()

總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
Django 內(nèi)置權(quán)限擴(kuò)展案例詳解
這篇文章主要介紹了Django 內(nèi)置權(quán)限擴(kuò)展案例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
淺析python 內(nèi)置字符串處理函數(shù)的使用方法
這篇文章主要介紹了python 內(nèi)置字符串處理函數(shù)的使用方法,需要的朋友可以參考下2014-06-06
Python各種擴(kuò)展名區(qū)別點(diǎn)整理
在本篇文章里小編給大家整理的是關(guān)于Python各種擴(kuò)展名區(qū)別點(diǎn)整理,需要的朋友們可以學(xué)習(xí)下。2020-02-02
Python利用pdfplumber提取PDF文檔中的表格數(shù)據(jù)并導(dǎo)出
pdfplumber是一個功能強(qiáng)大的Python庫,可以用于解析PDF文檔并提取其中的文本、表格和圖像等內(nèi)容,下面我們就來學(xué)習(xí)一下如何使用pdfplumber提取PDF表格數(shù)據(jù)吧2023-12-12
django框架中ajax的使用及避開CSRF 驗證的方式詳解
這篇文章主要介紹了django框架中ajax的使用及避開CSRF 驗證的方式,結(jié)合實例形式分析了Django框架ajax后臺交互與排除驗證csrf相關(guān)操作技巧,需要的朋友可以參考下2019-12-12

