Take the 2-minute tour ×

I am making a group of subplot (say, 3 x 2) in matplotlib, but I have fewer than 6 datasets. How can I make the remaining subplot blank?

The arrangement looks like this:

| 0,0| 0,1|
| 1,0| 1,1|
| 2,0| 2,1|

This may go on for several pages, but on the final page, there are, for example, 5 datasets to the 2,1 box will be empty. However, I have declared the figure as:

cfig,ax = plt.subplots(3,2)

So in the space for subplot 2,1 there is a default set of axes with ticks and labels. How can I programatically render that space blank and devoid of axes?

share|improve this question
this question helped a lot! +1 –  hello_there_andy Nov 6 at 17:07

3 Answers 3

up vote 18 down vote accepted

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

import matplotlib.pyplot as plt

hf, ha = plt.subplots(3,2)
ha[-1, -1].axis('off')


and results in the following figure:

enter image description here

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).

share|improve this answer
Thanks - that's actually even closer to my original question. I already accepted the other answer and adapted my code to use it, but both approaches are great. –  mishaF Apr 5 '12 at 21:06
Cool, that's indeed nice as there's less add_subplot() clutter. –  moooeeeep Apr 5 '12 at 21:12
@mishaF This is why you should wait a while before accepting an answer. Accepting an answer too soon may put people off investisting the time to suggest an alternative answer. Remember, however, that you can always change the accepted answer (not that I am suggesting you do, but you always can). –  Chris Apr 6 '12 at 9:55
@Chris - I totally agree, and sorry that yours came in after I had accepted. I'd feel bad rescinding my initial accepting, but I will for sure hold off in the future. I upvoted it though :) –  mishaF Apr 10 '12 at 2:21
on second thought - such a better fit, that I switched.... –  mishaF Apr 10 '12 at 2:22

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 plt

ax1 = 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))


enter image description here

share|improve this answer
Wow - that's a nice improvement. So much simpler! Thanks @Hooked! –  mishaF Jan 24 '13 at 21:56

Would it be an option to create the subplots when you need them?

import matplotlib
import matplotlib.pyplot as plt

plt.suptitle("Figure Title")
share|improve this answer
I don't think so because there are other formatting things I need to do that I didn't include in the original question for brevity. One of these is plt.subplots_adjust(wspace=0,hspace=0). I'm not sure that would work after the fact. –  mishaF Apr 5 '12 at 20:44
@mishaF : you can do subplots_adjust() using this approach. See my edit. –  moooeeeep Apr 5 '12 at 20:54
sure enough - that works fine! Thanks tons!! –  mishaF Apr 5 '12 at 20:57

Your Answer


