Python中的 Matplotlib.axes.Axes.eventplot()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.eventplot()函数
matplotlib 库的 axes 模块中的Axes.eventplot()函数用于在给定位置绘制相同的平行线。
Syntax: Axes.eventplot(self, positions, orientation=’horizontal’, lineoffsets=1, linelengths=1, linewidths=None, colors=None, linestyles=’solid’, *, data=None, **kwargs)
Parameters: This method accept the following parameters that are described below:
- positions : This parameter is the sequence of objects and each value is an event.
- orientation: This parameter is used to controls the direction of the event collections {‘horizontal’, ‘vertical’}.
- lineoffsets: This parameter is the offset of the center of the lines from the origin, in the direction orthogonal to orientation.
- linelengths: This parameter is the total height of the lines.
- linewidths: This parameter is the line width(s) of the event lines, in points.
Returns: This returns the following:
- list: This returns the list of EventCollection objects.
下面的示例说明了 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()