How can I make a blank subplot in matplotlib? How can I make a blank subplot in matplotlib? python python

How can I make a blank subplot in matplotlib?


You could always hide the axes which you do not need. For example, the following code turns off the 6th axes completely:

import matplotlib.pyplot as plthf, ha = plt.subplots(3,2)ha[-1, -1].axis('off')plt.show()

and results in the following figure:

An image of a 3x2 grid of graphs, with no graph rendered in the bottom right cell

Alternatively, see the accepted answer to the question Hiding axis text in matplotlib plots for a way of keeping the axes but hiding all the axes decorations (e.g. the tick marks and labels).


A much improved subplot interface has been added to matplotlib since this question was first asked. Here you can create exactly the subplots you need without hiding the extras. In addition, the subplots can span additional rows or columns.

import pylab as pltax1 = plt.subplot2grid((3,2),(0, 0))ax2 = plt.subplot2grid((3,2),(0, 1))ax3 = plt.subplot2grid((3,2),(1, 0))ax4 = plt.subplot2grid((3,2),(1, 1))ax5 = plt.subplot2grid((3,2),(2, 0))plt.show()

enter image description here


It's also possible to hide a subplot using the Axes.set_visible() method.

import matplotlib.pyplot as pltimport pandas as pdfig = plt.figure()data = pd.read_csv('sampledata.csv')for i in range(0,6):    ax = fig.add_subplot(3,2,i+1)    ax.plot(range(1,6), data[i])    if i == 5:        ax.set_visible(False)