0

I'm just want to get base64 string of plot image(png) from matplotlib in remote ubuntu server by python for serving to web page.

But, it is not working in remote server(ubuntu14.04, python3) like below.

    plt.plot(date, created, 'b', label='Created')
    plt.plot(date, closed,  'r', label='Closed')

    buf = io.BytesIO()
    plt.savefig(buf, format='png')
    img_base64 = base64.b64encode(buf.getvalue()).decode('utf8')
    plt.close()
    buf.close()

_tkinter.TclError: no display name and no $DISPLAY environment variable

Please help me...

Tj Kim
  • 15
  • 4
  • See [Matplotlib in a web application server](http://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server) – Galen Dec 16 '17 at 02:48

1 Answers1

1

You want to use:

import matplotlib
matplotlib.use('Agg')

Here's the relevant documentation.

ghart
  • 36
  • 3