欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python繪制莖葉圖的示例代碼

 更新時(shí)間:2024年01月09日 10:29:01   作者:微小冷  
這篇文章主要為大家信息介紹了Python繪制莖葉圖的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

簡(jiǎn)介

莖葉圖從外觀來(lái)看,更像是火柴,由基線、莖線、莖頭三部分構(gòu)成。最簡(jiǎn)單的示例如下

import numpy as np
import matplotlib.pyplot as plt
plt.stem(np.sin(np.arange(10)))
plt.show()

參數(shù)

stem的完整參數(shù)如下

stem([locs,] heads, linefmt=None, markerfmt=None, basefmt=None, bottom=0, label=None, orientation='vertical', data=None)

其中

  • locs和heads表示其x , y x,yx,y方向的值。如果只輸入一組數(shù)值,則默認(rèn)輸入的是heads。
  • linefmt, markerfmt, basefmt 均為字符串,分別用于定義莖線、莖頭以及基線的格式。
  • orientation 表示莖葉圖方向,默認(rèn)為’vertical’,若取值為’horizontal’,則莖葉圖調(diào)轉(zhuǎn)90°
  • bottom 為基線的位置
  • label 為圖例中使用的標(biāo)簽

linefmt和basefmt字符串由兩部分組成,分別用于設(shè)置莖線的顏色和類(lèi)型,第一部分格式為Cx,表示色環(huán)中第x種顏色;第二部分可選’-', ‘–’, ‘-.’, ‘:’,表示線的虛實(shí)類(lèi)型。當(dāng)然,第一部分直接采取顏色縮寫(xiě),比如r,g,b也是可以的。

markerfmt也是同樣的格式,但用于調(diào)整莖頭標(biāo)記點(diǎn)的字符與線型有所差異。其具體可選值存放在Line2D中

from matplotlib.lines import Line2D
 from pprint import pprint
 pprint(Line2D.markers)

打印結(jié)果是一個(gè)字典,列表如下

0‘tickleft’1‘tickright’2‘tickup’
3‘tickdown’4‘caretleft’5‘caretright’
6‘caretup’7‘caretdown’8‘caretleftbase’
9‘caretrightbase’10‘caretupbase’11‘caretdownbase’
‘’‘nothing’’ ’‘nothing’‘*’‘star’
‘+’‘plus’‘,’‘pixel’‘.’‘point’
‘1’‘tri_down’‘2’‘tri_up’‘3’‘tri_left’
‘4’‘tri_right’‘8’‘octagon’‘<’‘triangle_left’
‘>’‘triangle_right’‘D’‘diamond’‘H’‘hexagon2’
None’‘nothing’‘P’‘plus_filled’‘X’‘x_filled’
‘^’‘triangle_up’‘_’‘hline’‘d’‘thin_diamond’
‘h’‘hexagon1’‘none’‘nothing’‘o’‘circle’
‘p’‘pentagon’‘s’‘square’‘v’‘triangle_down’
‘x’‘x’‘vline’

演示

下面演示一下不同格式的效果

lf = ['C0-', 'C1--', 'C2-.', 'C3:']
mf = ['C40', 'r*', 'g8', 'bD']

xs = np.sin(np.arange(10))

fig = plt.figure()
for i in range(4):
    ax = fig.add_subplot(2,2,i+1)
    ax.stem(xs, linefmt=lf[i], markerfmt=mf[i])
    plt.title(f"linefmt={lf[i]}, markerfmt={mf[i]}")

plt.show()

效果如下

到此這篇關(guān)于Python繪制莖葉圖的示例代碼的文章就介紹到這了,更多相關(guān)Python莖葉圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論