Open In App

matplotlib.axes.Axes.step() in Python

Last Updated : 13 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.step() Function

The Axes.errorbar() function in axes module of matplotlib library is used to make a step plot..

Syntax:

Axes.step(self, x, y, *args, where='pre', data=None, **kwargs)

Parameters: This method accept the following parameters that are described below:

  • x, y: These parameter are the horizontal and vertical coordinates of the data points.
  • fmt: This parameter is an optional parameter and it contains the string value.
  • data: This parameter is also an optional parameter. And it is the object with labelled data.
  • where: This parameter is also an optional parameter. And it is used to define where the steps should be placed. The values are {‘pre’, ‘post’, ‘mid’}. pre is the default value

Returns: This returns the following:

  • lines:This returns the list of Line2D objects representing the plotted data.

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

Example-1:




# Implementation of matplotlib function
      
import numpy as np
import matplotlib.pyplot as plt
  
x = np.arange(16)
y = np.sin(x / 3)
  
fig, ax = plt.subplots()
  
ax.step(x, y + 2, color ='green')
ax.plot(x, y + 2, 'o--', color ='black', alpha = 0.3)
  
ax.set_title('matplotlib.axes.Axes.step Example1')
plt.show()


Output:

Example-2:




# Implementation of matplotlib function
      
import numpy as np
import matplotlib.pyplot as plt
  
x = np.arange(16)
y = np.sin(x / 3)
  
fig, ax = plt.subplots()
  
ax.step(x, y + 2, label ='pre (default)')
ax.plot(x, y + 2, 'o--', color ='black', alpha = 0.3)
  
ax.step(x, y + 1, where ='mid', label ='mid')
ax.plot(x, y + 1, 'o--', color ='black', alpha = 0.3)
  
ax.step(x, y, where ='post', label ='post')
ax.plot(x, y, 'o--', color ='black', alpha = 0.3)
  
ax.grid(axis ='x', color ='0.95')
ax.legend(title ='Parameter where:')
ax.set_title('matplotlib.axes.Axes.step Example2')
plt.show()


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads