0

I want to save a matplotlib chart so I can reference it later as an email attachment.
Following is the code to create the chart; I tried using savefig(). It creates a file but the file is empty when I open it.
Can someone tell me what I've done wrong?

x = (list(today['STOCH'][60:104]))
plt.plot(x,label='Stochastics')
plt.ylabel('STOCH')
plt.xlabel('60 Min Chart\n78 Ticks per Day')
plt.title(stock)
plt.legend()
plt.show()
plt.savefig('stoch.png')
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
pmillerhk
  • 171
  • 1
  • 2
  • 12

1 Answers1

-1

You must save the figure before showing it, otherwise, it is closed when you try to save it, and the file is empty.

x = (list(today['STOCH'][60:104]))
plt.plot(x,label='Stochastics')
plt.ylabel('STOCH')
plt.xlabel('60 Min Chart\n78 Ticks per Day')
plt.title(stock)
plt.legend()

plt.savefig('stoch.png')     # <-- here

plt.show()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80