Saturday, November 16, 2024
Google search engine
HomeLanguagesMatplotlib.axes.Axes.eventplot() in Python

Matplotlib.axes.Axes.eventplot() in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.

matplotlib.axes.Axes.eventplot() Function

The Axes.eventplot() function in axes module of matplotlib library is used to plot identical parallel lines at the given positions.

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.

Below examples illustrate the matplotlib.axes.Axes.eventplot() function in matplotlib.axes:

Example #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()


Output:

Example #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()


Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments