I want to plot a 3-D surface with the axis in the middle of the figure.
I use the following code to plot the figure:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1, 1, 10)
y = np.linspace(-1, 1, 10)
X, Y = np.meshgrid(x, y)
Z = np.array([[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291],
[2.58677481, 3.22528864, 3.65334814, 3.86669336, 3.86399048,
3.64525411, 3.21186215, 2.56819809, 1.72989472, 0.78569291]])
fig = plt.figure()
ax = plt.axes(projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, linewidth=0,
cmap='viridis', edgecolor='none', antialiased=False)
ax.set_xlim(-1.01, 1.01)
fig.colorbar(surf, shrink=0.5, aspect=5)
# Plot the axis in the middle of the figure
xline=((min(X[:,0]),max(X[:,0])),(0,0),(0,0))
ax.plot(xline[0],xline[1],xline[2],'grey')
yline=((0,0),(min(Y[:,1]),max(Y[:,1])),(0,0))
ax.plot(yline[0],yline[1],yline[2],'grey')
zline=((0,0),(0,0),(min(Z[:,2]),max(Z[:,2])))
ax.plot(zline[0],zline[1],zline[2],'grey')
ax.view_init(30,220) # Camera angel
ax.set_title('surface');
By using the above code, I obtain the figure like this
What I really want is to plot a 3-D axis origin figure like the following:
How to eliminate the margin and put the axis in the middle of the graph?