0

yesterday i switched to Linux and i want to write a little Python program:

import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
linie, spannung = np.genfromtxt("werte.csv", delimiter=",", unpack = True)
d = (linie -1)*6
params, covariance_matrix = np.polyfit(d, spannung, deg = 1, cov = True)
errors = np.sqrt(np.diag(covariance_matrix))

print(params, errors)

plt.plot(d, spannung)
x = np.linspace(0,50,100)    
plt.plot(x,params[0]*x-params[1])
plt.show()

But unfortunately i get the error:

UserWarning: Matplotlib is currently using pgf, which is a non-GUI backend, so cannot show the figure.

I am new to Ubuntu and new to programming so I dont have a clue what that means.

Hopefully you can help me : )

Tibebes. M
  • 6,940
  • 5
  • 15
  • 36
Reaxon
  • 11
  • Does this answer your question? [when i use matplotlib in jupyter notebook,it always raise " matplotlib is currently using a non-GUI backend" error?](https://stackoverflow.com/questions/37365357/when-i-use-matplotlib-in-jupyter-notebook-it-always-raise-matplotlib-is-curren) – ChrisGPT was on strike Apr 25 '20 at 12:36

1 Answers1

0

Since you are working on a headless console you are getting this error use plt.savefig()

import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
linie, spannung = np.genfromtxt("werte.csv", delimiter=",", unpack = True)
d = (linie -1)*6
params, covariance_matrix = np.polyfit(d, spannung, deg = 1, cov = True)
errors = np.sqrt(np.diag(covariance_matrix))

print(params, errors)

plt.plot(d, spannung)
x = np.linspace(0,50,100)    
plt.plot(x,params[0]*x-params[1])
plt.savefig('anyname.png')
benai
  • 69
  • 1
  • 4