Linux server; Without X's. It is necessary to save the histogram in a separate file without displaying on the screen, respectively.

Found such code example:

img = cv2.imread('home.bmp',0) plt.hist(img.ravel(),256,[0,256]) 

When launching swears:

 no display name and no $DISPLAY environment variable 

How to save a histogram to a file? I tried different options from the Internet, tried through matplotlib, but also did not work ... I tried to write down an option, like:

 plt.savefig('histogram.jpg') 
  • Isn't it easier to use PIL and make a histogram pixel by pixel? - Vladimir Latypov

1 answer 1

Matplotlib defaults to Xwindows.

Decision:

 matplotlib.use('Agg')