pythonmatplotlib

How can I create png with matplotlib


I built a small piece of code to plot some data.

I built it on my Oracle VirtualBox and it worked.

I moved it to production, and had the sys admin install the code and the libraries, etc.

Now the matplotlib.pyplot section is failing.

I tried a simple snippet

from matplotlib.pyplot import *
time = [0, 1, 2, 3]
position = [0, 100, 200, 300]
plt.plot(time, position)
plt.xlabel('Time (hr)')
plt.ylabel('Position (km)')

and get...

qt.qpa.screen: QXcbConnection: Could not connect to display

I don't even want to see this on the screen, I just want to create a png for a web site.

How can the code be re-written to connect to the display?


Solution

  • take off the "plt." and it will work

    from matplotlib.pyplot import *
    time = [0, 1, 2, 3]
    position = [0, 100, 200, 300]
    plot(time, position)
    xlabel('Time (hr)')
    ylabel('Position (km)')