How to Remove Axes in Python matplotlib
Code1
If you want to hide the axes on a graph, you can use plt.axis('off')
(or False instead of ‘off’). This will make both the x and y axes disappear.
If you wish to remove only one of the axes, you can apply a method like the example below to the current figure’s axis object, plt.gca()
.
import numpy as np
import matplotlib.pyplot as plt
plt.subplots(figsize=(15,3))
plt.subplot(1,4,1)
plt.plot(x,y)
plt.subplot(1,4,2)
plt.plot(x,y)
plt.gca().axes.xaxis.set_visible(False) #x축만 없애기
plt.subplot(1,4,3)
plt.plot(x,y)
plt.gca().axes.yaxis.set_visible(False) #y축만 없애기
plt.subplot(1,4,4)
plt.plot(x,y)
plt.axis('off') #x,y축 모두 없애기
plt.show()
Environment
- OS: Windows10
- Version: Python 3.7.12, matplotlib 3.2.2