Reputation: 477
I have the following data:
dictionary=pd.DataFrame({"State":[1,4,3,6,2,4,9],"Economy":[45,32,45,12,34,56,45]})
I run a for loop to visualize the data. It makes two charts for each State and Economy.
for i in dictionary.keys():
pd.DataFrame(dictionary[i]).plot()
plt.savefig('all.png')
The plt.savefig
creates a picture only of the last (second) chart. How can I save both charts as png or other format images. Even if I remove the indent before plt.savefig('all.png')
it still doesn't work.
Upvotes: 0
Views: 943
Reputation: 4189
How can u expect 2 figures with the same name under the same directory?
dictionary=pd.DataFrame({"State":[1,4,3,6,2,4,9],"Economy":[45,32,45,12,34,56,45]})
for i in dictionary.keys():
pd.DataFrame(dictionary[i]).plot()
plt.savefig('all_{}.png'.format(i))
Upvotes: 1