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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right





My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.