Python | Step Line Plot

In this tutorial, we are going to learn how to create a Step-Line plot using matplotlib?
Submitted by Anuj Singh, on August 03, 2020

The Step Plot is one the most used data visualization techniques used in discrete analysis and Matplotlib has provided a function for Step plotting i.e. matplotlib.pyplot.plot(ls='steps').

The following are the few examples to illustrate how to use Step Line Plot in matplotlib?

Python | Step Line Plot (1)

Python | Step Line Plot (2)

Python | Step Line Plot (3)

Python code for step line plot

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
y = np.sin(x)*np.exp(x/5)

plt.figure()
plt.plot(x,y, ls='steps')
plt.title('Step Line Plot')
plt.grid()
plt.show()

plt.figure()
plt.plot(x,y, ls='steps', color=  'purple')
plt.title('Step Line Plot')
plt.grid()
plt.show()

plt.figure()
plt.plot(x,y, ls='steps', linewidth=4.0, color=  'purple')
plt.title('Step Line Plot')
plt.grid()
plt.show()

plt.figure()
plt.plot(x,y, ls='steps')
plt.plot(x,-(y+0.5), ls='steps')
plt.title('Step Line Plot')
plt.grid()
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.