0

I am creating a scatter plot with the below code.

trace3 =  go.Scatter(   
    x=tmp_attr.sort_index().index,
    y=tmp_attr.sort_index().values,
    yaxis = 'y2',
    name='% Buy', opacity = 0.6,
    marker=dict(
        color='black',
        line=dict(color='#000000',
                  width=2 )

    )

How do I add text corresponding to the y value for each (x,y) pair in the graph?

1 Answer 1

1

Simply define text and mode

    text=[f"{v:.2f}" for v in tmp_attr.sort_index().values],
    mode="text+lines"

full MWE

import plotly.graph_objects as go
import pandas as pd
import numpy as np

# simulate some data
tmp_attr = pd.Series(np.sin(np.linspace(0, 6.2, 15)))

trace3 = go.Scatter(
    x=tmp_attr.sort_index().index,
    y=tmp_attr.sort_index().values,
    yaxis="y2",
    name="% Buy",
    opacity=0.6,
    marker=dict(color="black", line=dict(color="#000000", width=2)),
    text=[f"{v:.2f}" for v in tmp_attr.sort_index().values],
    mode="text+lines"
)

go.Figure(trace3)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.