tin*_*can 6 python plotly plotly.graph-objects
当我尝试将 add_trace 添加到 sunbplots 时,出现此错误。该图是一个图形对象对象。
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)
Run Code Online (Sandbox Code Playgroud)
当使用没有行或列的子图时,这些图正常绘制。
小智 7
我遇到了同样的错误,以下内容对我有用:https ://github.com/plotly/plotly.py/issues/3315#issuecomment-1164393438
您需要在函数specs的参数中指定图表类型make_subplots。下面是一个 2x2 子图示例。
fig = make_subplots(
rows=2,
cols=2,
start_cell="top-left",
specs=[
[{"type": "scatter3d"}, {"type": "scatter3d"}],
[{"type": "scatter3d"}, {"type": "scatter3d"}]
]
)
Run Code Online (Sandbox Code Playgroud)