我写了一个函数,绘制了一个由两个不同大小的子图组成的图:
def draw_plot(data, function, sigma_value):
gs = gridspec.GridSpec(1, 5)
ax1 = subplot(gs[0, 0:3])
ax2 = subplot(gs[0, 3:5], sharey=ax1)
gs.update(wspace=0.05)
...
Run Code Online (Sandbox Code Playgroud)
我应该提到这是一个模块级函数,因此在该模块的顶部我进行了导入
from pylab import *
import matplotlib.gridspec as gridspec
Run Code Online (Sandbox Code Playgroud)
当我跑步时myplot.draw_plot(...),我明白了RuntimeError.事情是这种行为是不一致的.我可以调用该函数,比方说,三次,前两次我得到错误,而第三次运行OK.
追溯是
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "myplot.py", line 105, in draw_plot
ax1 = subplot(gs[0, 0:3])
File "C:\Python32\lib\site-packages\matplotlib\pyplot.py", line 766, in subplot
a = fig.add_subplot(*args, **kwargs)
File "C:\Python32\lib\site-packages\matplotlib\figure.py", line 779, in add_subplot
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "C:\Python32\lib\site-packages\matplotlib\axes.py", …Run Code Online (Sandbox Code Playgroud)