To hide the axis, you have to call matplotlib.pyplot.axis()
function and pass 'off'
or False
to it. It is important to note that this function will hide both the X-axis and Y-axis.
import matplotlib.pyplot as plt x = [1,2,3,4,5,6] y = [1,2,3,4,5,6] plt.axis('off') plt.plot(x, y) plt.show()
Output
If you want to hide X-axis, then follow the below procedure:
plt.gca()
function.xaxis.set_visible(False)
on the axes object obtained in the previous step to hide the x-axis.import matplotlib.pyplot as plt x = [1,2,3,4,5,6] y = [1,2,3,4,5,6] ax = plt.gca() ax.xaxis.set_visible(False) plt.plot(x, y) plt.show()
Output
If you want to hide Y-axis, then follow the below procedure:
plt.gca()
function.yaxis.set_visible(False)
on the axes object obtained in the previous step to hide the y-axis.import matplotlib.pyplot as plt x = [1,2,3,4,5,6] y = [1,2,3,4,5,6] ax = plt.gca() ax.yaxis.set_visible(False) plt.plot(x, y) plt.show()
Output
Note: axes.get_xaxis()
and axes.get_yaaxis()
are discouraged by Matplotlib documentation so it is recommended that you avoid using these two functions.