Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subplot with facet_col_wrap has unexpected behavior when referring to rows #3903

Closed
valankar opened this issue Sep 26, 2022 · 4 comments
Closed

Comments

@valankar
Copy link

Not sure what the problem here is but it is very confusing. I'm trying to add a hline to a subplot using facet_col_wrap. When I specify the row to add_hline(), it doesn't actually add it to the proper row.

The code I have is as follows:

#!/usr/bin/env python3
"""Test plot."""
import pandas as pd
import plotly.express as px


def main():
    """Test plot."""
    test_df = pd.read_csv('test.csv', index_col=0, parse_dates=True,
                          infer_datetime_format=True)
    line = px.line(
        test_df, x=test_df.index, y=test_df.columns, facet_col='variable', facet_col_wrap=2,
    )
    line.add_hline(y=100000, row=3, col=1)
    with open('test.html', 'w', encoding='utf-8') as out_file:
        out_file.write(line.to_html())


if __name__ == '__main__':
    main()

Here is a screenshot of the web page generated:

subplot

As you can see, the line gets added to row 1 instead of row 3.

The input CSV file is attached:

test.csv

@nicolaskruchten
Copy link
Contributor

Rows are numbered from the bottom in Plotly, similar to how the origin for a cartesian plot is in the bottom-left. I'm sorry this has caused confusion for you!

@valankar
Copy link
Author

Ah, I see. Thanks!

@nicolaskruchten
Copy link
Contributor

Clarification: in Plotly Express they're numbered from the bottom, because PX calls make_subplots internally with start_cell='bottom-left'

@valankar
Copy link
Author

I see, thanks. I think this is mainly what confused me, because I was also using make_subplots directly and expected the same behavior with Plotly Express.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants