I want to plot a 3D surface by using data from three different columns in a dataframe. I was able to do a scatter Plot and I added on it a color map. It works perfectly!
Now I am using trisurf with the same dataset. I have a plot but I am not able to apply a gradient of color on the plot. This is what I have done so far :
ttm = df_iv['nb of days to expiration'].tolist()
strikes = df_iv['Strike'].tolist()
imp_vol = df_iv['IV with Newton Method'].tolist()
xx = np.linspace(np.min(strikes), np.max(strikes))
yy = np.linspace(np.min(ttm), np.max(ttm))
xx, yy = np.meshgrid(xx, yy)
zz = interpolate.griddata((strikes, ttm), imp_vol, (xx.ravel(), yy.ravel()))
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(xx.ravel(), yy.ravel(), zz,c=zz,cmap='viridis')
cb = plt.colorbar(line)
ax.set_ylabel('Time to Maturity')
ax.set_xlabel('Strike Price')
ax.set_zlabel('Implied Volatility')
ax.grid(False)
ax.set_title ('Plot of the implied volatility surface')
plt.show()
Where df_iv
is the dataframe
containing the data required for the plot.
Unfortunately, the program returns:
Poly3DCollection object has no property c
.
Do you have a solution?
Thank you in advance!