当前有效matplotlib
版本为:3.4.1
。
概述
eventplot()
函数的作用是在给定位置绘制长度相同的平行线。
这种图形通常在神经科学中用于表示神经事件,通常称为尖峰栅格(spike raster
)、点栅格( dot raster
)或栅格图(raster plot
)。也可用于显示多组离散事件的时间或位置。
函数的签名为matplotlib.pyplot.eventplot(positions, orientation='horizontal', lineoffsets=1, linelengths=1, linewidths=None, colors=None, linestyles='solid', *, data=None, **kwargs)
。
函数的参数为:
-
positions
:一个一维类数组结构定义了一个事件序列的位置;由类数组结构构成的列表可以表示多组事件,每组事件都可以单独设置lineoffsets
、linelengths
、linewidths
、colors
、linestyles
等参数。不建议使用二维数据结构。类型为类数组或类数组列表。必备参数。 -
orientation
:时间序列的方向。取值范围为{'horizontal', 'vertical'}
。默认值为'horizontal'
。可选参数。 -
lineoffsets
:直线中心相对于原点的偏移量,垂直于orientation
,如果positions
参数为二维结构,该参数可为序列,长度应与positions
一致。类型为浮点数或类数组,默认值为1
。可选参数。 -
linelengths
:线条的高度的总和(即lineoffset - linelength/2 to lineoffset + linelength/2
),如果positions
参数为二维结构,该参数可为序列,长度应与positions
一致。类型为浮点数或类数组,默认值为1
。可选参数。 -
linewidths
:线条的宽度,单位为像素点,如果positions
参数为二维结构,该参数可为序列,长度应与positions
一致。类型为浮点数或类数组,默认值为rcParams["lines.linewidth"]
即1.5
。可选参数。 -
colors
:线条的颜色,如果positions
参数为二维结构,该参数可为序列,长度应与positions
一致。类型为颜色值或颜色值列表,默认值为rcParams["lines.color"]
,默认值为'C0'
。可选参数。 -
linestyles
:线条的样式,如果positions
参数为二维结构,该参数可为序列,长度应与positions
一致。类型为字符串、元组、字符串或元组的列表。默认值为'solid'
。有效的字符串范围为['solid', 'dashed', 'dashdot', 'dotted', '-', '--', '-.', ':']
,元组的形式应为(offset, onoffseq)
,onoffseq
是一个以像素点为单位的断断续续的元组。 -
**kwargs
:matplotlib.collections.BrokenBarHCollection
对象属性。
返回值为matplotlib.collections.EventCollection
对象列表。
案例:演示eventplot()
函数
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus']=False
data1 = np.random.random([6, 50])
colors1 = ['C{}'.format(i) for i in range(6)]
lineoffsets1 = [-9, -13, 1, 15, 6, 10]
linelengths1 = [5, 2, 3, 4, 3, 5]
plt.eventplot(data1, colors=colors1,
lineoffsets=lineoffsets1,
linelengths=linelengths1)
plt.show()