Может быть, это должно работать.
#!/usr/bin/env python
import pandas as pd
import numpy as np
from numpy.linalg import inv
#%% Function
def PlaneFit(x, y, z):
Mat1 = np.array([ [x.sum(), y.sum(), x.size],
[(x**2).sum(), (x*y).sum(), x.sum()],
[(z*x).sum(), (z*y).sum(), z.sum()],
])
Mat2 = np.array([ [z.sum()], [(x*z).sum()], [(z**2).sum()] ])
Mat = np.dot( inv(Mat1), Mat2 )
m, n, d = float(Mat[0]), float(Mat[1]), float(Mat[2])
return m, n, d
#%% values of z
df = pd.read_csv('output.csv', usecols=range(0, 31), header = None)
df_1 = df[0:31]
z = np.array(df_1)
#%% x and y
x = np.linspace(0, 1, 31)
y = np.linspace(0, 1, 31)
x, y = np.meshgrid(x, y)
#%% call function and make plane
m, n, d = PlaneFit(x, y, z)
Zplane = m* x + n* y + d
#%% Plotting
from mpl_toolkits.mplot3d import axes3d;
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, edgecolor='k', cmap='viridis', alpha = 0.99 ,linewidth=0, rstride=1, cstride=1,
antialiased=True, shade=False )
ax.plot_surface(x, y, Zplane, edgecolor='k', color='cyan' )
plt.show()