I'm trying to plot a 3D surface plot, using a fourth variable as a color scale. The distribution of the three input variables is not regularly spaced, but I think I already solved that part using the griddata method. Each one of the variables is a list with 20 values inside, one of the variables is the output of a numerical code using the other 3 variables. The idea is to use 2 of the input variables plus the output of the numerical code for the surface plot, and using the third input variable for the color scale. When I'm trying to use the value of the other variable for the color scale using the facecolor argument I haven´t be able to produce the right plot. I already tried to normalize the values of this variable to interval 0-1, and several other ways but in the majority of cases I just get a plot with a uniform color or some Type error. Below you can find the code that I'm trying to run.
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import griddata
import matplotlib
#opening the files with the 4 variables
p1=open('par1log10.txt','r')
p2=open('par2log10.txt','r')
p3=open('par3log10.txt','r')
output=open('response.txt','r')
par1, par2, par3, output1 = ([] for i in range(4))
for a in p1:
par1.append(float(a))
for b in p2:
par2.append(float(b))
for c in p3:
par3.append(float(c))
for d in output:
output1.append(float(d))
p1.close()
p2.close()
p3.close()
output.close()
data1=np.array(par1)
data2=np.array(par2)
data3=np.array(par3)
output=np.array(output1)
fig = plt.figure()
xi = np.linspace(data1.min(),data1.max(),200)
yi = np.linspace(data2.min(),data2.max(),200)
wi = np.linspace(data3.min(),data3.max(),200)
# Interpoling unstructured data
zi = griddata((data1, data2), output, (xi[None,:], yi[:,None]), method='cubic')
# removing NaNs from the array
zi = np.nan_to_num(zi)
ax = fig.add_subplot(1, 1, 1, projection='3d', azim=210)
xig, yig = np.meshgrid(xi, yi)
#normalizing variable to interval 0-1
data3col=data3/data3.max()
surf = ax.plot_surface(xig, yig, zi, rstride=1, cstride=1, facecolor=cm.jet(data3col), linewidth=0, antialiased=False, shade=False)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
#fig.colorbar(surf, shrink=0.5, aspect=5)
ax.set_zlim(0, 350000)
plt.show()
This version of the code just shows a blue surface, I also have tried, unsuccessfully, to build my own colormap based on the values of a list and then used that colormap, but without results. This is my first question here, so I hope I didn't violate any rules or made any mistakes. Any help will be greatly valued.