I have 3 rows data used as X,Z, Y separately. But Z data is directly read from a csv file, so it's not a function of (x,y).
The data shows:
[[0.00000000e+00 1.00000000e-01 2.00000000e-01 3.00000000e-01
3.09958506e-01 3.20000000e-01 3.25000000e-01 3.50000000e-01
3.75000000e-01 4.00000000e-01 5.00000000e-01 6.00000000e-01
7.00000000e-01]
[1.31722083e+06 1.31722083e+06 1.31722083e+06 1.31722089e+06
1.31722121e+06 1.31722083e+06 1.31722098e+06 1.31722134e+06
1.31722101e+06 1.31722083e+06 1.31738292e+06 3.92708000e+12
7.93453000e+12]
[1.42000000e+02 1.42000000e+02 1.42000000e+02 1.42000000e+02
1.42000000e+02 1.42000000e+02 1.42000000e+02 1.42000000e+02
1.42000000e+02 1.42000000e+02 1.42000000e+02 1.42000000e+02
1.42000000e+02]]
I referred this answer: Simplest way to plot 3d surface given 3d points
And my code is:
mat = pd.read_csv('results2.csv', header=None,sep=',').values
mat = mat[0:3,:13]
#print(mat)
Sparsity1 = mat[0,:]
agents1 = mat[2,:]
optimal1 = mat[1,:]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax = Axes3D(fig)
#ax.plot_surface(Sparsity1,agents1, optimal1, rstride=1, cstride=1, cmap=cm.viridis)
ax.plot_trisurf(Sparsity1, agents1, optimal1, linewidth=0, antialiased=False)
surf = ax.plot_trisurf(Sparsity1, agents1, optimal1, cmap=cm.jet, linewidth=0)
fig.colorbar(surf)
plt.show()
How can I make 3d plot with surface? It always tells me:
RuntimeError: Error in qhull Delaunay triangulation calculation: singular input data (exitcode=2); use python verbose option (-v) to see original qhull error.
If I use np.meshgrid(x,y), then I got the error:
ValueError: Argument Z must be 2-dimensional”
How can I fix this?
Thanks in advance!