I want to create a nice graph in python, so I used plotly to create a graph, but I get an error.
Maybe because I'm new to plotly
, I don't understand the error in this code.
The only thing I can tell is that my code is wrong.
I want to display multiple graphs in plotly.
fig = make_subplots(rows=math.ceil(len(file_names)/3),cols=3)
for j in range(len(file_names)):
df_inst = df_list[j][df_list[j]["species"] == species_list[int(10)]]
fig.append_trace(
px.scatter(
x=df_inst[" VG"],
y=df_inst[" ID"],
), row=1 + int(j / 3), col=1 + j % 3
)
fig.update_xaxes(type='linear' if xaxis_type == 'Linear' else 'log',
row=1 + int(j / 3), col=1 + j % 3)
fig.update_yaxes(type='linear' if yaxis_type == 'Linear' else 'log',
row=1 + int(j / 3), col=1 + j % 3)
fig.show()
erorr message.
ValueError:
Invalid element(s) received for the 'data' property of
Invalid elements include: [Figure({
'data': [{'hovertemplate': 'x=%{x}<br>y=%{y}<extra></extra>',
'legendgroup': '',
'marker': {'color': '#636efa', 'symbol': 'circle'},
'mode': 'markers',
'name': '',
'orientation': 'v',
'showlegend': False,
'type': 'scatter',
'x': array([-0.5 , -0.498, -0.496, ..., 0.996, 0.998, 1. ]),
'xaxis': 'x',
'y': array([ 1.8000e-13, 1.0200e-12, -1.6700e-12, ..., 1.5398e-06, 1.5725e-06,
1.5883e-06]),
'yaxis': 'y'}],
'layout': {'legend': {'tracegroupgap': 0},
'margin': {'t': 60},
'template': '...',
'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'x'}},
'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'y'}}}
})]
The 'data' property is a tuple of trace instances
that may be specified as:
- A list or tuple of trace instances
(e.g. [Scatter(...), Bar(...)])
- A single trace instance
(e.g. Scatter(...), Bar(...), etc.)
- A list or tuple of dicts of string/value properties where:
- The 'type' property specifies the trace type
One of: ['area', 'bar', 'barpolar', 'box',
'candlestick', 'carpet', 'choropleth',
'choroplethmapbox', 'cone', 'contour',
'contourcarpet', 'densitymapbox', 'funnel',
'funnelarea', 'heatmap', 'heatmapgl',
'histogram', 'histogram2d',
'histogram2dcontour', 'image', 'indicator',
'isosurface', 'mesh3d', 'ohlc', 'parcats',
'parcoords', 'pie', 'pointcloud', 'sankey',
'scatter', 'scatter3d', 'scattercarpet',
'scattergeo', 'scattergl', 'scattermapbox',
'scatterpolar', 'scatterpolargl',
'scatterternary', 'splom', 'streamtube',
'sunburst', 'surface', 'table', 'treemap',
'violin', 'volume', 'waterfall']
- All remaining properties are passed to the constructor of
the specified trace type
(e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])
Thank you for reading.
According to the documentation on adding traces to subplots, the
add_trace
andappend_trace
methods only take accept plotlygraph_objects
. Therefore, your code block:... should be changed to the following:
Here is an example where we can plot some a randomly generated DataFrame on different subplots adding Scatter
graph_objects
one at a time withappend_trace
: