plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16k stars 2.53k forks source link

enable plotly express figure composition #2647

Open nicolaskruchten opened 4 years ago

nicolaskruchten commented 4 years ago

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

JayPalm commented 4 years ago

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!

vcmorini commented 4 years ago

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.

nicolaskruchten commented 4 years ago

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!

dkapitan commented 3 years ago

@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
nicolaskruchten commented 3 years ago

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.

Naseefop commented 2 years ago

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

ericchansen commented 2 years ago

I am also hoping for this functionality.

atar-axis commented 1 year ago

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

lopez-hector commented 6 months ago

Just pinging this. Would be helpful.

gvwilson commented 2 months ago

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

Grisly00 commented 1 month ago

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.

nzjrs commented 4 weeks ago

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