Reputation: 107
I would like to plot several plots in a subplot, specifically ecdf plots which are found under plotly express. Unfortunately I cannot get it to work because it appears subplot expects a graph objects plotly plot. The error says it receives invalid data, specifically:
"Invalid element(s) received for the 'data' property"
Obviously that means that of the following, ecdf is not included: ['bar', 'barpolar', 'box', 'candlestick', 'carpet', 'choropleth', 'choroplethmapbox', 'cone', 'contour', 'contourcarpet', 'densitymapbox', 'funnel', 'funnelarea', 'heatmap', 'heatmapgl', 'histogram', 'histogram2d', 'histogram2dcontour', 'icicle', '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']
Great, now, is there a work around that will allow me to plot a few of these guys next to each other?
Here's the code for a simple ecdf plot as from the documentation.
import plotly.express as px
df = px.data.tips()
fig = px.ecdf(df, x="total_bill", color="sex", markers=True, lines=False, marginal="histogram")
fig.show()
If I wanted to plot two of this same plot together for example, I would expect the following code (basically copied from the documentation) to work, probably, (if it accepted ecdf) but I cannot get it to work for the aforementioned reasons.
from plotly.subplots import make_subplots
import plotly.graph_objects as go
df = px.data.tips()
fig = make_subplots(rows=1, cols=2)
fig.add_trace(
px.ecdf(df, x="total_bill", color="sex", markers=True, lines=False, marginal="histogram"),
row=1, col=1
)
fig.add_trace(
px.ecdf(df, x="total_bill", color="sex", markers=True, lines=False, marginal="histogram"),
row=1, col=2
)
fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")
fig.show()
Is there a work around for px.ecdf subplots?
Thank you in advance!
Upvotes: 1
Views: 2539
Reputation: 31226
face_col
parameter https://plotly.com/python-api-reference/generated/plotly.express.ecdf.htmlmake_subplots()
and px.ecdf()
create multiple x and y axis. It would be necessary to manage all of these yourselfimport plotly.express as px
import pandas as pd
df = px.data.tips()
df = pd.concat([px.data.tips().assign(col=c) for c in ["left","right"] ])
fig = px.ecdf(df, x="total_bill", color="sex", markers=True, lines=False, marginal="histogram", facet_col="col")
fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")
Upvotes: 2