當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Matplotlib.axes.Axes.eventplot()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。

matplotlib.axes.Axes.eventplot()函數

matplotlib庫的axiss模塊中的Axes.eventplot()函數用於在給定位置繪製相同的平行線。

用法: Axes.eventplot(self, positions, orientation=’horizontal’, lineoffsets=1, linelengths=1, linewidths=None, colors=None, linestyles=’solid’, *, data=None, **kwargs)


參數:此方法接受以下描述的參數:

  • positions:此參數是對象的序列,每個值是一個事件。
  • orientation:此參數用於控製事件集合{“水平”,“垂直”}的方向。
  • lineoffsets:此參數是線的中心在與方向正交的方向上偏離原點的偏移量。
  • linelengths:此參數是線條的總高度。
  • linewidths:此參數是事件線的線寬(以磅為單位)。

返回值:這將返回以下內容:

  • list:這將返回EventCollection對象的列表。

以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.eventplot()函數:

範例1:

#Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib 
  
  
matplotlib.rcParams['font.size'] = 8.0
   
np.random.seed(789680) 
data1 = np.random.random([6, 50]) 
  
colors1 = ['C{}'.format(i) for i in range(6)] 
lineoffsets1 = np.array([-9, -13, 1,  
                         15, 6, 10]) 
  
linelengths1 = [5, 2, 9, 11, 3, 5] 
   
fig, axs = plt.subplots() 
axs.eventplot(data1, colors=colors1,  
              lineoffsets=lineoffsets1, 
              linelengths=linelengths1) 
  
axs.set_title('matplotlib.axes.Axes.eventplot Example') 
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib 
  
  
matplotlib.rcParams['font.size'] = 8.0
  
np.random.seed(789680) 
data1 = np.random.gamma(4, size =[60, 50]) 
  
lineoffsets1 = 1
linelengths1 = 1
  
fig, [axs1, axs2]= plt.subplots(2, 1) 
axs1.eventplot(data1, colors ='green', 
               lineoffsets = lineoffsets1,  
               linelengths = linelengths1) 
  
axs2.eventplot(data1, colors ='green', 
               lineoffsets = lineoffsets1, 
               linelengths = linelengths1,  
               orientation ='vertical') 
  
axs1.set_title('matplotlib.axes.Axes.eventplot Example') 
plt.show()




相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axes.Axes.eventplot() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。