[英]creating a 3d surface graph in plotly
I have the following data:我有以下数据:
I'm trying to plot x=long, y=short, z=balance我正在尝试绘制 x=long, y=short, z=balance
I've done it like this:我是这样做的:
fig.add(go.Scatter3d(x=results['long'], y=results['short'], z=results['balance']))
and I get something like that:我得到了类似的东西:
what I am really looking for is a surface, like this example:我真正要找的是一个表面,就像这个例子:
so, following the example's code, I did:所以,按照示例的代码,我做了:
fig.add_surface(x=results['long'], y=results['short'], z=results['balance'], row=2, col=1)
but:但:
not only it doesn't display any data, it seems to totally ignore the subplot layout and draws over everything.它不仅不显示任何数据,而且似乎完全忽略了子图布局并绘制了所有内容。
here is the complete code:这是完整的代码:
fig = make_subplots(rows=2, cols=1, specs=[[{'type': 'xy'}], [{'type': 'scene'}]])
fig.add_trace(go.Scatter(x=series1['timestamp'], y=series1['data'], line_color='red', name='series 1'), row=1, col=1)
fig.add_trace(go.Scatter(x=series2['timestamp'], y=series2['data'], line_color='blue', name='series 2'), row=1, col=1)
fig.update_yaxes(title_text="USD", row=1, col=1)
fig.add_surface(x=results['long'], y=results['short'], z=results['balance'], row=2, col=1)
fig.show()
so, my questions are:所以,我的问题是:
Two answers:两个答案:
surface
traces accept a 2-d matrix for z
surface
轨迹接受z
二维矩阵layout.scene
object which is distinct from a 2-d cartesian subplot layout.scene
对象中,该对象与 2-d 笛卡尔子图不同Try 3D Surface plot from docs( here ).尝试文档中的 3D Surface plot(这里)。 Below provide example of it.
下面提供它的例子。 As I think, you can change
z_data
- and that's all, what you need:我认为,您可以更改
z_data
- 这就是您所需要的:
import plotly.graph_objects as go
import pandas as pd
# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')
fig = go.Figure(data=[go.Surface(z=z_data.values)])
fig.update_layout(title='Mt Bruno Elevation', autosize=False,
width=500, height=500,
margin=dict(l=65, r=50, b=65, t=90))
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.