1

I am plotting some data using pylab and everything works perfect as I expect. I have 6 different graphs to plot and I can individually plot them in separate figures. But when I try to subplot() these graphs, the last one (subplot(3,2,6)) doesn't show anything.

What confuses me is that this 6th graph is drawn perfectly when put in a separate figure but not in the subplot - with identical configurations.

Any ideas what may be causing the problem ?

Michael W
  • 690
  • 1
  • 9
  • 22
y33t
  • 649
  • 4
  • 14
  • 23
  • 1
    I am glad you sorted out your own problem, however could you add some example code so this will be more helpful for future users. – tacaswell Apr 21 '13 at 16:55

2 Answers2

1

I found out that subplot() should be called before the plot(), issue resolved.

y33t
  • 649
  • 4
  • 14
  • 23
1

In general, if you are working with more than one axes or writing non-interactive scripts it is better to use the OO interface, rather than the state-machine (MATLAB-like) interface. You could do this as:

fig, sub_lst = plt.subplots(3, 2)
sub_lst = sub_lst.ravel() # flatten list
for sub_p in sub_lst:
    sub_p.plot(...)
    # what ever other plotting commands you use

Note that the plotting functions are member functions of the axes objects returned by subplots.

See How can I attach a pyplot function to a figure instance? for a longer discussion of the OO vs state-machine interfaces

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199