简体   繁体   中英

Plotly Plot surface 3D not displayed

I really can't find an answer on the forum. I want to create a 3d surface with plotly offline. I use sample points. The scene displays empty without a surface. Please help, thanks.

import pandas as pd
import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
from plotly.graph_objs import *
init_notebook_mode()
df3=pd.DataFrame({'x':[1,2,3,4,5], 'y':[10,20,30,20,10], 'z':[5,4,3,2,1]})

trace0= Surface(x=df3['x'], y=df3['y'], z=df3['z'])
data=[trace0]
fig=dict(data=data)
plot(fig)

The problem is you haven't defined a surface of data, since your z data is just one-dimensional. For example, this should show a surface:

import pandas as pd
import numpy as np
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
from plotly.graph_objs import *
init_notebook_mode()

df3=pd.DataFrame({
    'x':[1,2,3,4,5],
    'y':[10,20,30,20,10],
    'z':[[5,4,3,2,1]] * 5
})

trace0= Surface(x=df3['x'], y=df3['y'], z=df3['z'])
data=[trace0]
fig=dict(data=data)
plot(fig)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM