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 ?

4

2 回答 2

1

我发现应该在 plot() 之前调用 subplot(),问题已解决。

于 2013-04-21T16:21:50.600 回答
1

一般来说,如果您使用多个轴或编写非交互式脚本,最好使用 OO 接口,而不是状态机(类似 MATLAB)接口。你可以这样做:

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

请注意,绘图函数是axes返回的对象的成员函数subplots

请参阅如何将 pyplot 函数附加到图形实例?有关 OO 与状态机接口的更长讨论

于 2013-04-21T17:03:40.473 回答