日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python繪制棉棒圖的方法詳解_python

作者:Vergil_Zsh ? 更新時間: 2022-05-27 編程語言

用法:

matplotlib.pyplot.stem(*args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, label=None, use_line_collection=True, orientation='vertical', data=None)

參數說明

參數 ?
*args x,y,x—棉棒的x軸基線的取值范圍,y—棉棒的長度
linefmt 棉棒的樣式,{‘-’,’–’,’:’,’-.’},包括指定顏色等
markerfmt 棉棒末端的樣式
basefmt 指定基線的樣式
bottom 默認值為0,極限的y/x的位置,取決于方向
label 用于標簽
use_line_collection 默認值是True,如果為True,棉棒的莖線存儲并繪制為線集合,而不是單獨的線,這將顯著提高性能,而不是單獨的線
orientation 控制方向,默認為垂直(True).

案例

參數

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
# 生成模擬數據集
x=np.linspace(0,10,20)
y=np.random.randn(20)
# 繪制棉棒圖
markerline, stemlines, baseline = plt.stem(x,y,linefmt='-',markerfmt='o',basefmt='--',label='TestStem')
# 可單獨設置棉棒末端,棉棒連線以及基線的屬性
plt.setp(markerline, color='k')#將棉棒末端設置為黑色
plt.legend()
plt.show()

在這里插入圖片描述

總結

原文鏈接:https://blog.csdn.net/KIKI_ZSH/article/details/123659896

欄目分類
最近更新