What's the issue with my code for visualizing linear regression in 3 dimensions with matplotlib? I am trying to use linear regression that takes two variables &quot;Idade&quot; and &quot;LF&quot; and tries to predict a third one, &quot;DGAF&quot;. I'm trying to both do the scatterplot with the observations and the model prediction on the same graph. Bellow is the code I used (using Python).
X = df[[&quot;Idade&quot;,&quot;LF&quot;]]
y = df[&quot;DGAF&quot;].values.reshape(len(df[&quot;DGAF&quot;]),1)

reg = LinearRegression()
reg.fit(X, y)

fig = plt.figure()
ax = Axes3D(fig)

ax.scatter(X['Idade'],X['LF'], y,s=10)

x_pred = np.linspace(0,100,1000)
y_pred = np.linspace(0,100,1000)
xx_pred, yy_pred = np.meshgrid(x_pred, y_pred)

model_viz = np.array([xx_pred.flatten(), yy_pred.flatten()]).T

ax.set_xlabel('Years since oil change')
ax.set_ylabel('LF')
ax.set_zlabel('DGA Score')

ax.plot(model_viz[0], model_viz[1], reg.predict(model_viz),color='red')
plt.show()

I get this error:
ValueError: input operand has more dimensions than allowed by the axis remapping

I am able to do the scatterplot, the issue seems to be with plotting the prediction. How can I solve this?
Following the suggestion given by @Ubikuity, I changed the ax.plot to ax.scatter, but there were still some issues with the dimensions. It was due to the transposition of the matrices, that was being done in the wrong place. The code below works correctly.
X = df[[&quot;Idade&quot;,&quot;LF&quot;]]
y = df[&quot;DGAF&quot;].values.reshape(len(df[&quot;DGAF&quot;]),1)

reg = LinearRegression()
reg.fit(X, y)

fig = plt.figure()
ax = Axes3D(fig)

ax.scatter(X['Idade'],X['LF'], y,s=10)

x_pred = np.linspace(0,100,100)
y_pred = np.linspace(0,100,100)
xx_pred, yy_pred = np.meshgrid(x_pred, y_pred)

model_viz = np.array([xx_pred.flatten(), yy_pred.flatten()])

ax.set_xlabel('Years since oil change')
ax.set_ylabel('LF')
ax.set_zlabel('DGA Score')

ax.scatter(model_viz[0], model_viz[1], reg.predict(model_viz.T),color='red')
plt.show()
```