Remove the axis lines from the Python plot

matplotlib.pyplot.box(): Here, we are going to learn how to removes the axis lines from the Python plot?
Submitted by Anuj Singh, on July 23, 2020

Sometimes, we need to hide the axis and to overlay other widgets over the plot and avoid the mess in the figure. For this purpose, matplotlib has a defined function matplotlib.pyplot.box(). It removes the axis lines from the plot and performs our desired operation.

Illustration:

Remove the axis lines from the Python plot (1)

Remove the axis lines from the Python plot (2)

Remove the axis lines from the Python plot (3)

Python code to remove the axis lines from the plot

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(50)

y = np.random.randint(45,55,50)

#Example 1
plt.figure()
plt.plot(x, y, 'o-')
plt.title('Example 1')
plt.ylabel('Numbers')
plt.xlabel('numbers')
plt.ylim(0,70)
plt.box()
plt.show()

#Example 2
plt.figure()
plt.bar(x, y, color='orange')
plt.title('Example 2 : Bar Plot')
plt.xlabel('numbers')
plt.ylabel('Numbers')
plt.ylim(0,70)
plt.box()
plt.show()

#Example 3
plt.figure()
plt.scatter(x, y, color='red', alpha=0.5)
plt.title('Example 3 : Scatter Plot')
plt.xlabel('numbers')
plt.ylabel('Numbers')
plt.ylim(0,70)
plt.grid()
plt.box()
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.