Issue
I'm trying to recreate a matplotlib surface plot with Plotly.
The matplotlib code:
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
ax.plot_trisurf(
data3["strike"],
dates.date2num(data3["expiration"]),
data3["GEX"],
cmap="seismic_r",)
ax.yaxis.set_major_formatter(dates.AutoDateFormatter(ax.xaxis.get_major_locator()))
ax.set_ylabel("Expiration date", fontweight="heavy")
ax.set_xlabel("Strike Price", fontweight="heavy")
ax.set_zlabel("Gamma (M$ / %)", fontweight="heavy")
plt.show()
The plot looks like this:
The dataframe is the following:
Now my code with plotly looks like this:
z = data3['GEX']
fig5 = go.Figure([go.Surface(z= [z,z],
x=data3['expiration'],
y=data3['strike'],
opacity=0.95,
connectgaps=False,
colorscale='reds',
showscale=True,
reversescale=False,
)
]
)
I read that in plotly the z-axis needs to be at least a 2D array. Which i'm still unsure on how to arrange the dataframe to meet this criteria.
The plot with the code above looks like this and only shows one y-axis value (381 in this case)
Solution
Since you are plotting a triangulated surface with plot_trisurf, you should use something similar with plotly, that is create_trisurf from the plotly.figure_factory module.
Answered By - Ratislaus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.