savefig的问题

时间:2019-06-27 16:17:49

标签: python-3.x matplotlib spyder

我编写的产生箱线图的代码运行良好,直到我尝试编辑其中的一个图形为止。现在,命令fig.savefig(或plt.savefig)根本不起作用。

以下代码在过去一个月中一直在Spyder中有效,直到今天。我尝试过在Jupyter Notebook和python raw中运行它,但无济于事。

fig = plt.figure(1, figsize=(9, 6))
ax = fig.add_subplot(111)
d = ['D-4','D-3','D-2','D-1','D']
p = sns.boxplot(data=cdo_mom) #Plots boxplots
plt.setp(p.artists,edgecolor='k') #Changes the colors of the boxes, whiskers, median lines
plt.setp(p.lines,color='k')
p.yaxis.grid(True) #Turns on the y axis grid
p.set_axisbelow(True)
p = sns.swarmplot(data=cdo_mom,color='black') #Displays raw data
p.set(xticklabels=d) #Sets the x label as the name of the volume
plt.text(0,3.4,'n: %s' % len(cdo_mom[0]),color='blue',ha='center',va='bottom') # displays number of observations for each volume
plt.text(1,3.04,'n: %s' % len(cdo_mom[1]),color='orange',ha='center',va='bottom')
plt.text(2,3.04,'n: %s' % len(cdo_mom[2]),color='green',ha='center',va='bottom')
plt.text(3,2.9,'n: %s' % len(cdo_mom[3]),color='red',ha='center',va='bottom')
plt.text(4,3.25,'n: %s' % len(cdo_mom[4]),color='purple',ha='center',va='bottom')
plt.ylim(bottom=0)
ax.get_xticklabels()[0].set_color('red')
ax.get_xticklabels()[1].set_color('red')
ax.get_xticklabels()[2].set_color('red')
ax.get_xticklabels()[3].set_color('red')
ax.set_title('D$_0$ Median of Medians For Corrected dataset',fontsize=18)
ax.set_ylabel('D$_0$ (mm)',fontsize=16)
ax.set_xlabel('Volume',fontsize=16)
fig.savefig(r'D:\Desktop\c_mom\D0_c_mom')
plt.close()

我希望这些数字将保存在我提供的目录中,但是同样,此代码在工作一个月后意外停止工作

0 个答案:

没有答案