Logical Retard
Logical Retard

Reputation: 143

Histogram image not getting saved

import numpy as np

import matplotlib.pyplot as plt

x=np.random.gamma( 2, 3, 100000)

plt.hist( x, bins=30)

plt.show()

plt.savefig("normalhistogram.png")

The above code is working perfectly for plotting histograms for gama distribution values, but the only problem is that I want to save the image of generated histogram but plt.savefig("normalhistogram.png") is creating a blank image everytime I execute the code instead of saving the histogram as image. I'm unable to figure out the issue here. Help?

Upvotes: 1

Views: 361

Answers (1)

DYZ
DYZ

Reputation: 57033

Do not show() the image before saving it. Showing the image clears the canvas. (But saving does not, so you can show the image after saving it.)

Upvotes: 2

Related Questions