0
我無法在matplotlib中顯示iPython中的圖像,圖像在彈出窗口中出現一秒而不是內聯,然後立即關閉。 Spyder內部的iPython控制檯中沒有任何內容出現。圖在matplotlib中不起作用
from statistics import mean
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import style
style.use('fivethirtyeight')
xs = np.array([1,2,3,4,5,6], dtype=np.float64)
ys = np.array([5,4,6,5,6,7], dtype=np.float64)
def best_fit_slop_and_intercept (xs,ys):
m = (((mean(xs)*mean(ys))-mean(xs*ys))/
((mean(xs)**2)-mean(xs**2)))
b = mean(ys)-m*mean(xs)
return m,b
m,b = best_fit_slop_and_intercept(xs,ys)
print (m,b)
regression_line = [m*x + b for x in xs ]
print (regression_line)
predict_x = 9
predict_y = predict_x*m + b
plt.scatter(predict_x,predict_y, color = 'g')
plt.scatter(xs,ys)
plt.plot(xs, regression_line)
plt.show()
確實嘗試在ipython中運行這個(沒有spyder)?我沒有spyder,但這段代碼對我來說運行良好。 (彈出一個窗口打開並保持,直到我退出) – putonspectacles