def PlotPolly(model, independent_variable, dependent_variabble, Name)。
x_new = np.linspace(15, 55, 100)
y_new = model(x_new)
plt.plot(independent_variable, dependent_variabble, '. ' , x_new, y_new, '-') #4
plt.title('Polynomial Fit with Matplotlib for Price ~ Length')
ax = plt.gca()
ax.set_facecolor((0.898, 0.898, 0.898)
fig = plt.gcf()
plt.xlabel(Name)
plt.ylabel('Price of Cars')
plt.show()
plt.close()
我用這段代碼得到了這個結果:
但是當我從第4行開始洗掉x_new和y_new行時,就變成了
plt.plot(independent_variable, dependent_variabble)
我得到了這個圖形 :
你能解釋一下x_new和y_new是什么意思,為什么沒有這個會導致這種圖形
uj5u.com熱心網友回復:在你的代碼中 輸出:
標籤: 上一篇:更改SVG文本x_new和y_new都有連續的值,但是independent_variable和dependent_variabble有不連續的值,為了繪制不連續你需要scatter plot。
import numpy as np
import matplotlib.pyplot as plt.
x = np. array([ 2, 1, 5, 3, 4, 2, 6, 4] )
y = np. array([3, 1, 2, 0, 1, 2, 6, 4] )
plt.plot(x, y, linestyle='-'/span>, marker='o'/span>)



