2016-10-29 5 views
0

이 스크립트를 작동 시키려고하지만 터미널에서 실행할 때마다 스크립트가 실행 중이더라도 렌더링되지 않습니다. Qt5Agg 백엔드를 사용하여 matplotlib 그래프를 렌더링 할 수 없습니다.

나는 윈도우 10 컴퓨터에

pip install Qt5Agg 

난을 사용하여 Qt5Agg를 설치했습니다.
파이썬 3.5를 사용합니다.
터미널에 오류가 없습니다.
스크립트에 필요한 모든 종속성이 있습니다. 모든

import csv 
import numpy as np 
from sklearn.svm import SVR 
import matplotlib.pyplot as plt 


plt.switch_backend('Qt5Agg') 



dates = [] 
prices = [] 

def get_data(filename): 
    with open(filename, 'r') as csvfile: 
     csvFileReader = csv.reader(csvfile) 
     next(csvFileReader) # skipping column names 
     for row in csvFileReader: 
      dates.append(int(row[0].split('-')[0])) 
      prices.append(float(row[1])) 
    return 

def predict_price(dates, prices, x): 
    dates = np.reshape(dates,(len(dates), 1)) # converting to matrix of n X 1 

    svr_lin = SVR(kernel= 'linear', C= 1e3) 
    svr_poly = SVR(kernel= 'poly', C= 1e3, degree= 2) 
    svr_rbf = SVR(kernel= 'rbf', C= 1e3, gamma= 0.1) # defining the support vector regression models 
    svr_rbf.fit(dates, prices) # fitting the data points in the models 
    svr_lin.fit(dates, prices) 
    svr_poly.fit(dates, prices) 

    plt.scatter(dates, prices, color= 'black', label= 'Data') # plotting the initial datapoints 
    plt.plot(dates, svr_rbf.predict(dates), color= 'red', label= 'RBF model') # plotting the line made by the RBF kernel 
    plt.plot(dates,svr_lin.predict(dates), color= 'green', label= 'Linear model') # plotting the line made by linear kernel 
    plt.plot(dates,svr_poly.predict(dates), color= 'blue', label= 'Polynomial model') # plotting the line made by polynomial kernel 
    plt.xlabel('Date') 
    plt.ylabel('Price') 
    plt.title('Support Vector Regression') 
    plt.legend() 
    plt.show() 

    return svr_rbf.predict(x)[0], svr_lin.predict(x)[0], svr_poly.predict(x)[0] 

get_data('deutch.csv') # calling get_data method by passing the csv file to it 
#print "Dates- ", dates 
#print "Prices- ", prices 

predicted_price = predict_price(dates, prices, 40) 

print(predicted_price) 

답변

1

첫째, 더 Qt5Agg이없는 나는, 당신은 PyQt5를 설치 한 가정 : 여기

는 스크립트입니다.

plt.switch_backend을 사용하면 안되며 여기 (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.switch_backend)의 설명서를 빠르게 살펴볼 수 있습니다.

import matplotlib 
matplotlib.use('Qt5Agg') 
import matplotlib.pyplot as plt 
: 그것을 가져 pyplot 후 백엔드를 변경할 수 없습니다로

은 다음과 같이 가져 오기 문을 변경

관련 문제