I'm trying to produce two different figures to separate files (.png images) that use the same basic data, but I get blank white images. However, both figures seem ok when shown in a jupyter notebook with plt.show() statement. My relevant code looks like:
plt.figure(1)
fig1, axs1 = plt.subplots(2,2)
plt.figure(2)
fig2, axs2 = plt.subplots(2,2)
# generate 4 datasets in a for loop
for i in range(4):
x,y = createRandomData(parameters)
fit1 = doFit1(x,y)
plt.figure(1)
axs1[i//2,i%2].plot(x,y,color='black',linewidth = 1)
axs1[i//2,i%2].plot(x,fit1,color='green',linewidth = 1)
fit2 = doFit2(x,y)
plt.figure(2)
axs2[i//2,i%2].plot(x,y,color='black',linewidth = 1)
axs2[i//2,i%2].plot(x,fit1,color='green',linewidth = 1)
plt.figure(1)
plt.gcf().set_size_inches(12,8)
plt.gcf().savefig('dataWithFit1.png', dpi=200)
plt.show()
plt.figure(2)
plt.gcf().set_size_inches(12,8)
plt.gcf().savefig('dataWithFit2.png', dpi=200)
plt.show()
Can't figure out why savefig() does not produce the corrent output even if following show() statements produce the correct output to browser inside jupyter notebook.
I have also tried variable fig1
instead of plt.gcf()
.
Any suggestions?