3

The 3D surface plot in plotly never shows the data, I get the plot to show up, but nothing shows up in the plot, as if I had ploted an empty Data Frame.

At first, I tried something like the solution I found here(Plotly Plot surface 3D not displayed), but had the same result, another plot with no data.

df3 = pd.DataFrame({'x':[1, 2, 3, 4, 5],'y':[10, 20, 30, 40, 50],'z': [5, 4, 3, 2, 1]})
iplot(dict(data=[Surface(x=df3['x'], y=df3['y'], z=df3['z'])]))

And so I tried the code at the plotly website(the first cell of this notebook: https://plot.ly/python/3d-scatter-plots/), exactly as it is there, just to see if their example worked, but I get an error.

I am getting this:

https://lh3.googleusercontent.com/sOxRsIDLVkBGKTksUfVqm3HtaSQAN_ybQq2HLA-aclzEU-9ekmvd1ETdfsswC2SdbysizOI=s151

But I should get this:

https://lh3.googleusercontent.com/5Hy2Z-97_vwd3ftKBA6dYZfikJHnA-UMEjd3PHvEvdBzw2m2zeEHBtneLC1jzO3RmE2lyw=s151

Observation: could not post the images because of lack of reputation.

1 Answers1

2

In order to plot a surface you have to provide a value for each point. In this case your x and y are series of size 5, that means that your z should have a shape (5, 5).

If I had a bit more info I could give you more details but for a minimal working example try to pass a (5, 5) dataframe, numpy array or even a list of lists to the z value of data.

EDIT:

In a notebook environment the following code works for me:

from plotly import offline
from plotly import graph_objs as go
offline.init_notebook_mode(connected=False)

df3 = {'x':[1, 2, 3, 4, 5],'y':[10, 20, 30, 40, 50],'z': [[5, 4, 3, 2, 1]]*5}
offline.iplot(dict(data=[go.Surface(x=df3['x'], y=df3['y'], z=df3['z'])]))

as shown here:

enter image description here

I'm using plotly 3.7.0.

vlizana
  • 2,962
  • 1
  • 16
  • 26
  • Even if z has a (5, 5) shape it still outputs an empty graphic: `df3 = pd.DataFrame({'x':[1, 2, 3, 4, 5],'y':[10, 20, 30, 20, 10],'z': [[5, 4, 3, 2, 1]] * 5}) iplot(dict(data=[Surface(x=df3['x'], y=df3['y'], z=df3['z'])]))` I have also attempted to create a separate z variable to use in the plot: `df3 = pd.DataFrame({'x':[1, 2, 3, 4, 5],'y':[10, 20, 30, 20, 10],'z': [[5, 4, 3, 2, 1]] * 5}) z = [[5, 4, 3, 2, 1]] * 5 iplot(dict(data=[Surface(x=df3['x'], y=df3['y'], z=z)]))` I also tried to use many other types of data for the variable z, such as numpy arrays, Series. – João Pedro Voga Apr 14 '19 at 18:45
  • And yes I am in a note book enviroment. – João Pedro Voga Apr 14 '19 at 18:46
  • Edited with a notebook code version, if it still doesn't work it must be something in the installation, try reinstalling plotly or something similar. – vlizana Apr 14 '19 at 21:02