考虑(假设代码运行没有错误):
import matplotlib.figure as matfig
ind = numpy.arange(N)
width = 0.50;
fig = matfig.Figure(figsize=(16.8, 8.0))
fig.subplots_adjust(left=0.06, right = 0.87)
ax1 = fig.add_subplot(111)
prev_val = None
fig.add_axes(ylabel = 'Percentage(%)',xlabel='Wafers',title=title,xticks=(ind+width/2.0,source_data_frame['WF_ID']))
fig.add_axes(ylim=(70,100))
for key,value in bar_data.items():
ax1.bar(ind,value, width,color='#40699C', bottom=prev_val)
if prev_val:
prev_val = [a+b for (a,b) in zip(prev_val,value)]
else:
prev_val=value
names= []
for i in range(0,len(col_data.columns)):
names.append(col_data.columns[i])
ax1.legend(names,bbox_to_anchor=(1.15, 1.02))
我现在想用 保存我的身材fig.savefig(outputPath, dpi=300)
,但我得到了AttributeError: 'NoneType' object has no attribute 'print_figure'
,因为fig.canvas
没有。子图应该在图形画布上,所以它不应该是无。我想我错过了一个关于 matplot 数字画布的关键概念。如何更新 fig.canvas 以反映当前的数字,所以我可以使用fig.savefig(outputPath, dpi=300)
?谢谢!