Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly subplots and graph objects error: Trace type 'scatter3d' is not compatible with subplot type 'xy' at grid position

I get this error when I try to add_trace to a sunbplots. The plot is a graph objects object.

fig = make_subplots(rows = len(dfbh['client'].value_counts().index.tolist()), cols = 1)
scatbh = go.Scatter3d(x=dfbhtemp['x_local'], y=dfbhtemp['y_local'], z=dfbhtemp['z_local'], mode = 'markers', )
scatrun = go.Scatter3d(x=dfrunstemp['x_local'], y=dfrunstemp['y_local'], z=dfrunstemp['z_local'], mode = 'markers')
fig.add_trace(scatbh, row = 1, col = 1)
fig.add_trace(scatrun, row = 1, col = 1)
fig.show()

ValueError:  Trace type 'scatter3d' is not compatible with subplot type 'xy'
at grid position (2, 1)

These plots plot normaly when using subplots with no rows or columns.

like image 520
tincan Avatar asked Apr 27 '26 01:04

tincan


1 Answers

I had the same error and the following worked for me: https://github.com/plotly/plotly.py/issues/3315#issuecomment-1164393438

You need to specify the chart type in the specs argument of the make_subplots function. Below is an example a 2x2 subplot figure.

fig = make_subplots(
    rows=2, 
    cols=2,
    start_cell="top-left", 
    specs=[
        [{"type": "scatter3d"}, {"type": "scatter3d"}], 
        [{"type": "scatter3d"}, {"type": "scatter3d"}]
    ]
)
like image 97
ryan.hausen Avatar answered Apr 29 '26 14:04

ryan.hausen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!