plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

enable plotly express figure composition

Open nicolaskruchten opened this issue 5 years ago • 12 comments

It would be really nice to be able to take two figures created with Plotly Express (or really anything else) and "glue them together" side by side or one above the other, something like fig3 = compose([fig1, fig2, fig3], orientation="h") or something even more powerful.

I love how ggplot patchwork https://github.com/thomasp85/patchwork and Altair https://altair-viz.github.io/user_guide/compound_charts.html do this!

See also Overlaying: #2648

nicolaskruchten avatar Jul 16 '20 20:07 nicolaskruchten

Just spent half an hour looking for a solution to this. Any progress made this week? I need to make some 2x2 subplots with different Y axes. Compose would be very helpful!

JayPalm avatar Jul 24 '20 21:07 JayPalm

This would be a necessary feature, already strongly suggested by the community. The solutions so far are either not native Plotly or depreciates the PX design, for example, by taking only the trace, and leaving the layout out. See: https://github.com/plotly/plotly_express/issues/83#issuecomment-529167965 In the mentioned way, the rug, color, etc, are totally ignored.

vcmorini avatar Aug 11 '20 14:08 vcmorini

If anyone wants to take this on, I'd be happy to review the code :) It's not on our short-term roadmap at the moment, despite how useful it would be!

nicolaskruchten avatar Aug 11 '20 16:08 nicolaskruchten

@nicolaskruchten

Am considering to take up this issue. Running into the following difficulty when trying to figure out a solution on Google Colab:

!pip install plotly==4.12.0

import pandas as pd
import plotly.express as px
from plotly.subplots import make_subplots


pd.options.plotting.backend = 'plotly'

# Ames Housing dataset
df = pd.read_csv('https://github.com/jads-nl/discover-projects/blob/main/ames-housing/AmesHousing.csv?raw=true')

fig = make_subplots(rows=1, cols=2, shared_xaxes=False, shared_yaxes=False)
fig.add_trace(df.SalePrice.hist().data[0], row=1, col=1)
fig.add_trace(df['Year Built'].hist().data[0], row=1, col=2)

The second histogram on the right does not render properly, something goed wrong with the axis and/or default values. I can't see which setting causes this. Could you give a pointer in the right direction perhaps? Screenshot 2020-11-21 at 11 49 16

dkapitan avatar Nov 21 '20 10:11 dkapitan

Hmm this last one is kind of funny... What's happening here is that both the traces you're extracting with data[0] have bingroup: "x" (where "x" is just an arbitrary string, but it's the PX default) and so the right-hand plot is getting all its data stuck in a single bin! Definitely something we'll have to manage with this composition issue!

If you run fig.update_traces(bingroup=None) after your code that'll clear the groups and each trace will be binned on its own.

nicolaskruchten avatar Nov 24 '20 18:11 nicolaskruchten

Any updates here?.
Spend 1-hour searching for a solution!!

Naseefop avatar Oct 14 '21 15:10 Naseefop

I am also hoping for this functionality.

ericchansen avatar Apr 04 '22 18:04 ericchansen

Please add this! I would also add some bugs to the bucket if needed. Where can I donate?

atar-axis avatar Nov 29 '22 02:11 atar-axis

Just pinging this. Would be helpful.

lopez-hector avatar Feb 21 '24 19:02 lopez-hector

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Alternatively, if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

gvwilson avatar Jul 08 '24 12:07 gvwilson

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Alternatively, if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

As far as I know there is still now way to make a composition of multiple figures created with Plotly Express. So yes, still an issue.

Grisly00 avatar Jul 16 '24 06:07 Grisly00

ig3 = compose([fig1, fig2, fig3], orientation="h") would be a perfect API for this.

nzjrs avatar Aug 15 '24 13:08 nzjrs