Skip to content

fig.add_line similar to add_(h|v)line #3370

@janosh

Description

@janosh

I often find myself needing a parity line (aka identity line, i.e. x = y) across the whole plot that cannot be zoomed/panned away similar to add_(h|v)line.

How about adding a new method fig.add_line() that takes an anchor point [x0, y0] = [0, 0] along with a slope = 1?

If the plot has equal x and y range, I currently use this as a workaround:

import plotly.graph_objects as go

fig = go.Figure()

line_dict = dict(
    type="line", yref="paper", y0=0, y1=1, xref="paper", x0=0, x1=1, opacity=0.1
)
fig.update_layout(shapes=[line_dict])

fig.update_xaxes(range=[0, 100])
fig.update_yaxes(range=[0, 100])

fig.write_image("tmp.png")

tmp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions