y33t
y33t

Reputation: 679

Python Pylab subplot bug?

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 ?

Upvotes: 1

Views: 424

Answers (2)

tacaswell
tacaswell

Reputation: 87376

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

Upvotes: 1

y33t
y33t

Reputation: 679

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

Upvotes: 1

Related Questions