python不会生成pdf文档



昨天我切换到Linux,我想写一个小Python程序:

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()

但不幸的是,我得到了错误:

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

我是Ubuntu的新手,也是编程的新手,所以我不知道这意味着什么。

希望你能帮我:(

由于您在无头控制台上工作,因此使用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')

相关内容

  • 没有找到相关文章

最新更新