10

This is a very simple question but I must misunderstand the use of pyplot and figure or something else. I'm plotting some images and would like to save them instead of just showing them and saving them by hand. So far I've tried:

import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot(d,c1[0:100],'b--',d,c2[0:100],'r--',d,c3[0:100],'g--',figure = fig) 
plt.ylabel("concentration")
plt.xlabel("distance")
plt.show()
plt.savefig('./Results/evol_conc_v'+str(vinit)+'a_'+str(a)+'.png')

The file created is blank, but the image showed was good. The existing similar question don't seem to apply.

alpagarou
  • 471
  • 2
  • 5
  • 11

1 Answers1

20

Get rid of the

plt.show()

or put it below the savefig call.

Or you do this

plt.show()
fig.savefig('./Results/evol_conc_v'+str(vinit)+'a_'+str(a)+'.png') # Use fig. here

since you already create a figure object at the beginning.

lmNt
  • 3,822
  • 1
  • 16
  • 22