matplotlib階梯圖的實(shí)現(xiàn)(step())
step函數(shù)概述
step
函數(shù)用于繪制階梯圖。
根據(jù)源碼可知,step
函數(shù)是對(duì)plot
函數(shù)的輕量級(jí)封裝,很多概念和用法與plot
函數(shù)非常相似。
def step(self, x, y, *args, where='pre', data=None, **kwargs): cbook._check_in_list(('pre', 'post', 'mid'), where=where) kwargs['drawstyle'] = 'steps-' + where return self.plot(x, y, *args, data=data, **kwargs)
step
函數(shù)簽名:
matplotlib.pyplot.step(x, y, *args, where='pre', data=None, **kwargs)
step
函數(shù)調(diào)用簽名:
step(x, y, [fmt], *, data=None, where='pre', **kwargs) step(x, y, [fmt], x2, y2, [fmt2], ..., *, where='pre', **kwargs)
其中:
- x:類數(shù)組結(jié)構(gòu),一維x軸坐標(biāo)序列。一般假設(shè)x軸坐標(biāo)均勻遞增。必備參數(shù)。
- y:類數(shù)組結(jié)構(gòu),一維y軸坐標(biāo)序列。必備參數(shù)。
- fmt:格式字符串,與plot函數(shù)的fmt參數(shù)類似??蛇x參數(shù)。官方建議只設(shè)置顏色格式。
- data:可索引數(shù)據(jù),類似于plot函數(shù)??蛇x參數(shù)。
- **kwargs:類似于plot函數(shù)。
- where :設(shè)置階梯所在位置,取值范圍為{'pre', 'post', 'mid'},默認(rèn)值為'pre'。
案例:使用step函數(shù)和plot函數(shù)演示不同where參數(shù)的效果
通過(guò)案例可知,step
函數(shù)可以認(rèn)為是plot
函數(shù)繪制階梯圖的一個(gè)特例。
import numpy as np import matplotlib.pyplot as plt x = np.arange(14) y = np.sin(x / 2) plt.figure(figsize=(12,5)) plt.subplot(121) plt.step(x, y + 2, label='pre (default)') plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3) plt.step(x, y + 1, where='mid', label='mid') plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3) plt.step(x, y, where='post', label='post') plt.plot(x, y, 'o--', color='grey', alpha=0.3) plt.grid(axis='x', color='0.95') plt.legend(title='Parameter where:') plt.title('plt.step(where=...)') plt.subplot(122) plt.plot(x, y + 2, drawstyle='steps', label='steps (=steps-pre)') plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3) plt.plot(x, y + 1, drawstyle='steps-mid', label='steps-mid') plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3) plt.plot(x, y, drawstyle='steps-post', label='steps-post') plt.plot(x, y, 'o--', color='grey', alpha=0.3) plt.grid(axis='x', color='0.95') plt.legend(title='Parameter drawstyle:') plt.title('plt.plot(drawstyle=...)') plt.show()
到此這篇關(guān)于matplotlib階梯圖的實(shí)現(xiàn)(step())的文章就介紹到這了,更多相關(guān)matplotlib 階梯圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python學(xué)習(xí)之使用Matplotlib畫(huà)實(shí)時(shí)的動(dòng)態(tài)折線圖的示例代碼
- Matplotlib animation模塊實(shí)現(xiàn)動(dòng)態(tài)圖
- matplotlib bar()實(shí)現(xiàn)多組數(shù)據(jù)并列柱狀圖通用簡(jiǎn)便創(chuàng)建方法
- matplotlib源碼解析標(biāo)題實(shí)現(xiàn)(窗口標(biāo)題,標(biāo)題,子圖標(biāo)題不同之間的差異)
- matplotlib繪制正余弦曲線圖的實(shí)現(xiàn)
- 詳解matplotlib繪圖樣式(style)初探
- matplotlib更改窗口圖標(biāo)的方法示例
- matplotlib繪制多子圖共享鼠標(biāo)光標(biāo)的方法示例
- python使用matplotlib的savefig保存時(shí)圖片保存不完整的問(wèn)題
- matplotlib 畫(huà)動(dòng)態(tài)圖以及plt.ion()和plt.ioff()的使用詳解
- matplotlib制作雷達(dá)圖報(bào)錯(cuò)ValueError的實(shí)現(xiàn)
相關(guān)文章
Pytorch中transforms.Resize()的簡(jiǎn)單使用
這篇文章主要介紹了Pytorch中transforms.Resize()的簡(jiǎn)單使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07pandas將numpy數(shù)組寫(xiě)入到csv的實(shí)例
今天小編就為大家分享一篇pandas將numpy數(shù)組寫(xiě)入到csv的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07Python中decimal.Decimal類型和float類型的比較
這篇文章主要介紹了Python中decimal.Decimal類型和float類型的比較,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11基于Python的XSS測(cè)試工具XSStrike使用方法
XSS(Cross Site Scripting,跨站腳本攻擊)是一類特殊的Web客戶端腳本注入攻擊手段,通常指攻擊者通過(guò)“HTML注入”篡改了網(wǎng)頁(yè),插入惡意的腳本,從而在用戶瀏覽網(wǎng)頁(yè)時(shí)控制瀏覽器的一種攻擊。2017-07-07利用python在Word文檔中創(chuàng)建和執(zhí)行條件郵件合并
郵件合并域和IF域是Word文檔中兩種非常實(shí)用的域,前者可以用來(lái)進(jìn)行郵件合并,根據(jù)數(shù)據(jù)批量創(chuàng)建定制的Word文檔,本文講介紹如何使用Python在Word文檔中創(chuàng)建條件郵件合并域以及執(zhí)行條件郵件合并,需要的朋友可以參考下2024-08-08用python記錄運(yùn)行pid,并在需要時(shí)kill掉它們的實(shí)例
下面小編就為大家?guī)?lái)一篇用python記錄運(yùn)行pid,并在需要時(shí)kill掉它們的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01python開(kāi)發(fā)之list操作實(shí)例分析
這篇文章主要介紹了python開(kāi)發(fā)之list操作方法,結(jié)合實(shí)例形式分析了list操作的具體用法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-02-02