[英]Can I plot only 3D coordinates using plotly?
How can I plot a 3D coordinate without any points on it? 如何绘制没有任何点的3D坐标? I tried to replace the z=z_data.as_matrix() with z = [] in the following code, but I didn't get anything. 我尝试在以下代码中将z = z_data.as_matrix()替换为z = [],但是我什么也没得到。
import plotly.offline as py
import plotly.graph_objs 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')
data = [
go.Surface(
z=z_data.as_matrix()
)
]
layout = go.Layout(
title='Mt Bruno Elevation',
autosize=False,
width=500,
height=500,
margin=dict(
l=65,
r=50,
b=65,
t=90
)
)
fig = go.Figure(data=data, layout=layout)
py.plot(fig, filename='elevations-3d-surface')
In order to plot 3D coordinates in Plotly, you need to provide 3 input lists/data frames/etc with the x
, y
and z
coordinates. 为了在Plotly中绘制3D坐标,您需要提供3个具有x
, y
和z
坐标的输入列表/数据框/等。
data = [
go.Scatter3d(
x=val_x,
y=val_y,
z=val_z,
mode='markers'
)
]
You can use the dataset linked in the question and convert it to such a list, eg 您可以使用问题中链接的数据集并将其转换为这样的列表,例如
# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')
# totally inelegant approach to convert the dataframe to a dictionary to convert it to a list
z_dict = z_data.to_dict()
val_x = []
val_y = []
val_z = []
for x in z_dict:
for y in z_dict[x]:
val_x.append(x)
val_y.append(y)
val_z.append(z_dict[x][y])
which will give you the following plot. 这将为您提供以下情节。
Complete code 完整的代码
import plotly.offline as py
import plotly.graph_objs 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')
# totally inelegant approach to convert the dataframe to a dictionary to convert it to a list
z_dict = z_data.to_dict()
val_x = []
val_y = []
val_z = []
for x in z_dict:
for y in z_dict[x]:
val_x.append(x)
val_y.append(y)
val_z.append(z_dict[x][y])
data = [
go.Scatter3d(
x=val_x,
y=val_y,
z=val_z,
mode='markers'
)
]
fig = go.Figure(data=data)
py.plot(fig, filename='elevations-3d-surface')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.