当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Matplotlib.pyplot.eventplot()用法及代码示例


Matplotlib是Python中令人惊叹的可视化库,用于二维阵列图。 Matplotlib是一个基于NumPy数组构建的multi-platform数据可视化库,旨在与更广泛的SciPy堆栈配合使用。

Matplotlib.pyplot.eventplot()

此函数通常用于在给定位置绘制相同的线。这些图通常用于表示神经科学中的神经事件,在更多情况下,它被称为尖峰栅格或点栅格或栅格图。通常,它还用于显示多组不同或离散事件的计时或位置。例如,在过去的十年或世纪中,员工每天上班的时间是每个月到公司的时间,或者每年飓风的日期是。

Syntax:: matplotlib.pyplot.eventplot(positions, orientation=’vertical’, lineoffsets=2, linelengths=2, linewidth= None, colors= None, linestyles=’solid’, *, data= None, **kwargs)



参数:

  • Positions: This parameter is generally a 1D or D array-like object where each value in the array represents an event. For a 2D array like position, each row corresponds to either a row or a column of the line which depends upon the orientation parameter. It is a required parameter for this method.
  • orientation: It is an optional argument which takes two values either ‘horizontal’ or ‘vertical’. It is responsible for controlling the direction of the event collections. If the passed value of orientation is ‘horizontal’ the lines are arranged horizontally in rows and are vertical whereas if the passed value is ‘vertical’ the lines are arranged vertically in columns and are horizontal
  • lineoffsets: This is an optional argument whose default value is 1. This parameter is used for plotting offset of the center of lines starting from the origin, which are orthogonal to the orientation of the plot. It accepts a scalar or sequence of scalars as its values.
  • linelengths: Similar to lineoffsets it is also an optional parameter whose default value is 1 and accepts scalar or a scalar sequence as its value. It is used to set the total height of the lines. It sets the stretches of the lines from lineoffset - linelength/2 to lineoffset + linelength/2.
  • linewidths: It is an optional parameter whose default value is None. It accepts scalar or scalar sequence or None as values. It is used to set the line width(s) of event lines in points. If it is set to None it defaults to its rcParams setting.
  • colors: As the name suggests it is used to set the colors of the event lines. It is an optional parameter whose default value is None. If the value is None it defaults to its rcParams setting. It takes color, the sequence of colors or None as a value.
  • linestyles: It is an optional parameter that takes a string, tuple or a sequence of strings or tuples as its value. The default value for this parameter is ‘solid’. The valid strings for this parameter are [‘solid’, ‘dashed’, ‘dashdot’, ‘dotted’, ‘-‘, ‘-‘, ‘-.’, ‘:’]. The dash tuples need to be in the form of (offset, onoffseq) where onoffseq is a tuple of on and off ink in points of even lengths.
  • **kwargs: It is an optional parameter. It generally accepts keywords from LineCollection properties.

返回:
This method returns a list of EventCollection objects which contains the EventCollection that were added.

注意:重要的是要注意,对于线长,线宽,颜色和线型,如果仅提供一个值,而不是将这些值应用于所有行,则对于array-like值,重要的是它与位置和每个值的长度相同应用于数组的相应行。

范例1:

import numpy as np 
import matplotlib.pyplot as plt 
  
positions = np.array([2, 4, 6])[:,np.newaxis] 
offsets = [2,4,6] 
  
plt.eventplot(positions, lineoffsets=offsets) 
plt.show()

输出:

python-matplotlib-eventplot-1

范例2:

import numpy as np 
import matplotlib.pyplot as plt 
  
spike = 100*np.random.random(100) 
plt.eventplot(spike,  
              orientation = 'vertical', 
              linelengths = 0.8,  
              color = [(0.5,0.5,0.8)])

输出:

python-matplotlib-eventplot-2




相关用法


注:本文由纯净天空筛选整理自RajuKumar19大神的英文原创作品 Matplotlib.pyplot.eventplot() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。