question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Figure.add_vline / add_hline mishandles the row argument, updates (n - row)th row

See original GitHub issue

It appears Figure.add_vline and add_hline mishandle the row parameter for faceted / subplot figures.

Current behavior: if a facet figure has n rows, passing row=k updates row n - k. Expected behavior: passing row=k updates the kth row

import numpy as np
import pandas as pd
import plotly.express as px

rng = np.random.default_rng(0)

df = pd.DataFrame(
    {
        "A": ([1, 2, 3] * 3) * 5,
        "B": ([4] * 3 + [5] * 3 + [6] * 3) * 5,
        "C": rng.uniform(size=(45,)),
        "D": rng.uniform(size=(45,)),
    }
)

fig = px.scatter(df, x="C", y="D", facet_col="A", facet_row="B")
fig.add_hline(y=0.7, row=1, col=1)
fig.add_vline(x=0.4, row=1, col=1)
fig.update_layout(width=500, height=500)

image

Plotly version: v5.10.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolaskruchtencommented, Oct 3, 2022

I agree this situation is quite confusing and we should have done things differently at the outset (and TBH I can’t recall what the decision-making process was that led us here!) but unfortunately we have very little appetite for backwards-incompatible changes for these years-old APIs that thousands of charts depend on 😦

0reactions
grisaitiscommented, Oct 3, 2022

Gotcha.

I still love plotly but, respectfully, I think this is counter-intuitive and confusing. Also I think it’s such a rare scenario that, in terms of API stability, there’d be more gain than pain in changing the call to make_subplots, which I see is here (hard-coded): https://github.com/plotly/plotly.py/blob/f83921fec9492e5ec415ff14aee3c1d9b245ad99/packages/python/plotly/plotly/express/_core.py#L2366

Also I think docs should mention the behavior of start_cell in Facet and Trellis Plots in Python and Subplots in Python, where there is no discussion currently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Horizontal and vertical lines and rectangles in Python - Plotly
Detailed examples of Horizontal and Vertical Lines and Rectangles including changing color, size, log axes, and more in Python.
Read more >
add_hline() breaks when axis is shared · Issue #3209 - GitHub
I have a multi-row, 1 col subplot with synced xaxis using fig.update_traces(xaxis=x<last subplot row>) . But, when I add vrect shapes, they only ......
Read more >
Plotly: How to add vertical line to plotly plot? - Stack Overflow
I am testing plotly express. I have the latest version: 0.4.1. I am trying to plot the most basic chart in their tutorial...
Read more >
Vertical line with constant x-value - MATLAB xline - MathWorks
This MATLAB function creates a vertical line at one or more x-coordinates in the ... constant line properties using one or more name-value...
Read more >
How can I make the vertical line of certain rows thicker in ...
I want to make a table and highlight a certain region in it using thick lines as shown below. Enter image description here....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found