plotly / plotly.py

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

`Figure.add_vline()` annotations and shape positions do not match on log plots #4012

Closed sharkweek closed 10 hours ago

sharkweek commented 1 year ago

When adding a vline to a plot with a logarithmic x-axis, the x parameter is interpreted differently for annotations than it is for the placement of the line. The lines are placed at the literal x-location on the x-axis, while annotations are placed at the 10^x location.

For example, using the literal location will produce the line as intended, but the annotations are missing because they're off at 10^25.

fig.add_vline(
    x=25,
    annotation_text='25'
)

lines

If I were to input the x parameter using the 10^n convention used throughout plotly for log plots, then I get the correct annotations, but the line will now be located off at log(25) (≈1.38).

fig.add_vline(
    x=np.log10(25),
    annotation_text='25'
)

annotations

I'm on Windows 10 using Plotly v5.9.0 and Python 3.9.15.

AaronStiff commented 1 year ago

Duplicate of #2580