Skip to content

annotation coordinates do not respect log scaling #2580

@eisenlohr

Description

@eisenlohr

When adding annotations to a plot that uses log scaling, the annotation coordinates need to be rescaled to represent the log10 of the actual coordinates. While this is documented behavior, it is rather counterintuitive and should be fixed.
Seemingly no other axis-types (date, for instance) needs special treatment but works without modifying the underlying data.

Minimum example demonstrating the point, i.e. label_y is 4 but plotted at 10^4:

df = pd.DataFrame(data={'x':[1,2,3,4],
                        'y':[1,4,9,16],
                        })

fig = px.line(df,
              x='x',
              y='y',
              log_y=True,
              log_x=True,
              )

annotations = []
fig.for_each_trace(
    lambda trace: annotations.append(dict(x=np.log10(np.sqrt(trace.x[0]*trace.x[-1])),
                                          y=np.sqrt(trace.y[0]*trace.y[-1]),
                                          text=f'({np.sqrt(trace.x[0]*trace.x[-1])},{np.sqrt(trace.y[0]*trace.y[-1])})',))
)

fig.update_layout(annotations=annotations,
                  width=300,
                  height=300,
                  )
fig.show()

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions