Js: Uncaught Error: cwise: Arrays do not all have the same shape!

I’m trying to use Plot.ly with Python to create a 3D Surface from a Pandas DataFrame. Nevertheless, the charts appears empty, and this error is shown in console:

js: Uncaught Error: cwise: Arrays do not all have the same shape!

I’m currently on Python 3.6.5 and Plot.ly 3.1.0. Any suggestion?

My code:

import plotly
import plotly.graph_objs as go
import pandas as pd

df = pd.read_csv('test.csv')
	
data = [go.Surface(x=df.strike,
				   y=df.expiration_date,
				   z=df.iv)]

layout = go.Layout(showlegend=True, title='IV surface')
fig = go.Figure(data=data, layout=layout)

raw_html = '<html><head><meta charset="utf-8" />'
raw_html += '<script src="{}"></script></head>'.format(plotly_lib)
raw_html += '<body>'
raw_html += plotly.offline.plot(fig, include_plotlyjs=False, output_type='div', link_text='')
raw_html += '</body></html>'

I suspect your ‘z’ there is a 1D column? At the moment, surface only accepts 2D array for ‘z’`.

Yes, all “x”, “y” and “z” are 1D arrays. I expected Surface to work as a 3D scatter plot where several points P(x,y,z) are shown, but where z is not the result of a formula F(x,y). Isn’t this possible?

I don’t understand why (nor how) z is described with a 2D array. Maybe because what I just described as my intention is not possible, and therefore I’m thinking out of the box about this.

EDIT: I edited it as a 2D array and it works, so thank you for your advice. Nevertheless, settings xaxis and yaxis at the layout has not worked for me: axis titles as ignored and only “X” and “Y” is written. Also, setting the “ticktext” parameter for xaxis and yaxis didn’t worked, and the axis is specified from 0 to N. This is a problem, since I’m supposed to be plotting dates on one axis, and non consecutive numbers in the other axis. Also, it amazes me that there is no zaxis property for the layout.

Any advice on that?

See 3d axes in JavaScript