1

I am using python on a linux shell and trying to save plot instead of displaying (displaying plot window leads to an error). I looked at question Save plot to image file instead of displaying it using Matplotlib, but didn't help. Here is my code:

import matplotlib.pyplot as plt
#
# list3 is list of data
plt.hist(list3, bins=10)
plt.xlabel('X')
plt.ylabel('Y')
fig.savefig('plot.png')

The problem is figure window is appearing even though I don't call plt.figure(). Is there any way to suppress graphical figure window and instead save plot to the file?

ewr3243
  • 397
  • 3
  • 19
  • using your code I'm not able to reproduce your error. ```plt.show()```display the figure, ```plt.figure()``` is supposed to be written before ```plt.hist``` if you want to tune some parameters (or display multiple figures for example). – Panda50 Apr 21 '21 at 14:51

1 Answers1

1

plt.savefig('plot.png') saves the png file for me. May be you need to give full path for the file

Amit Nanaware
  • 3,203
  • 1
  • 6
  • 19