How to Turn Off the Axes for Subplots in Matplotlib?
In this article, we are going to discuss how to turn off the axes of subplots using matplotlib module. We can turn off the axes for subplots and plots using the below methods:
Method 1: Using matplotlib.axes.Axes.axis()
To turn off the axes for subplots, we will matplotlib.axes.Axes.axis() method here.
Python3
# import required modulesimport matplotlib.pyplot as pltimport matplotlib.tri as mtriimport numpy as np # assign data x = np.asarray([0, 1, 2, 3, 0.5, 1.5, 2.5, 1, 2, 1.5])y = np.asarray([0, 0, 0, 0, 1.0, 1.0, 1.0, 2, 2, 3.0])triangles = [[0, 1, 4], [1, 5, 4], [2, 6, 5], [4, 5, 7], [5, 6, 8], [5, 8, 7], [7, 8, 9], [1, 2, 5], [2, 3, 6]]# depict illustrationtriang = mtri.Triangulation(x, y, triangles)z = np.cos(1.5 * x) * np.cos(1.5 * y) fig, axs = plt.subplots()axs.tricontourf(triang, z)axs.triplot(triang, 'go-', color ='white')# turn off the axesaxs.set_axis_off()# assign titleaxs.set_title('Triangle illustration')plt.show() |
Output:

Here, we turn off axes using the axis(“off”) statement.
Method 2: Using matplotlib.axes.Axes.set_axis_off()
We use matplotlib.axes.Axes.set_axis_off() to turn the x-and y-pivot off influencing the axis lines, ticks, ticklabels, network and axis marks as well.
Python3
# import required modulesimport matplotlib.pyplot as pltimport numpy as np # time series datageeksx = np.array([24.40, 110.25, 20.05, 22.00, 61.90, 7.80, 15.00])geeksy = np.array([24.40, 110.25, 20.05, 22.00, 61.90, 7.80, 15.00]) # depict illustration fig, ax = plt.subplots()ax.xcorr(geeksx, geeksy, maxlags = 6, color ="green")# turn off the axesax.set_axis_off()# assign titleax.set_title('Time series graph')plt.show() |
Output:

Method 3: Using matplotlib.pyplot.axis()
In a visualization, if the figure has a single plot in it, we can turn off the axes for subplots by making look like a contention to the matplotlib.pyplot.axis() technique. If the figure contains different subplots, this technique just turns off axes for the last subplot.
Python3
# importing moduleimport matplotlib.pyplot as plt# assigning x and y coordinatesx = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]y = []for i in range(len(x)): y.append(max(0, x[i]))# depicting the visualizationax = plt.plot(x, y, color='green')# turn off the axesplt.axis('off')# displaying the titleplt.title("ReLU function graph")plt.show() |
Output:

Here, we turn off axes using the plt.axis(“off”) statement.


