Sometimes, we want to remove axis, legends and white spaces in Python Matplotlib plots.
In this article, we’ll look at how to remove axis, legends and white spaces in Python Matplotlib plots.
How to removing axis, legends and white spaces in Python Matplotlib plots?
To remove axis, legends and white spaces in Python Matplotlib plots, we can call axis
and savefig
with some options.
For instance, we write
from numpy import random
import matplotlib.pyplot as plt
data = random.random((5,5))
img = plt.imshow(data, interpolation='nearest')
img.set_cmap('hot')
plt.axis('off')
plt.savefig("test.png", bbox_inches='tight')
to call plt.axis
with 'off'
to remove the axes.
And we call savefig
with bbox_inches
to 'tight'
to remove whitespaces.
Conclusion
To remove axis, legends and white spaces in Python Matplotlib plots, we can call axis
and savefig
with some options.