Rotate text annotations in go.Scatter plot

The first image is how the text annotation is required, the second image is what I am getting. There appears to be no method to rotate the text in Scatter plot. What option do I have wherein I can get a line at the point just like shown below as well as rotate the annotation?

The code:

fig = go.Figure()
#Epoch 2005
fig.add_traces(
    go.Scatter(
        name = '2005',
        x = Wav8071205,
        y = Int8071205
    )
)
#Epoch 2006
fig.add_traces(
    go.Scatter(
        name = '2006',
        x = Wav8101006,
        y = Int8101006
    )
)
#Epoch 2007
fig.add_traces(
    go.Scatter(
        name = '2007',
        x = Wav8110107,
        y = Int8110107
    )
)
#Epoch New
fig.add_traces(
    go.Scatter(
        name = 'New',
        x = Wav8fmcontr,
        y = Int8fmcontr
    )
)

#Add Lines with Wavelength
fig.add_traces(
    go.Scatter(
        x = [6563,8498, 8542, 8662],
        y = [-3,-3,-3,-3],
        mode="markers+text",
        marker_symbol = 'line-ns',
        marker_line_width=2, marker_size=20,
        text = ['H alpha','CaII a','CaII b','CaII c'],
        textposition = 'bottom center'
    )
)

fig.update_layout(
    title = 'Grism 8 Spectra',
    yaxis = dict(
        range=[-10,35]
    )
)
fig.show()

I am not sure why, but your example code does not run. However, you can use textangle=-90 within fig.add_annotation to rotate the annotation; may be that helps?

I have tried using that. But it did not work for me. The code doesn’t work because I have not included the files.

In this example it works

import plotly.graph_objects as go
animals=['giraffes', 'orangutans', 'monkeys']

fig = go.Figure(data=[
    go.Bar(name='SF Zoo', x=animals, y=[20, 14, 23]),
    go.Bar(name='LA Zoo', x=animals, y=[12, 18, 29])
])


fig.add_annotation(text="Absolutely-positioned annotation",
                  xref="paper", yref="paper",
                  x=0.8, y=0.7, showarrow=False,
                  textangle=-90)

config = dict({'scrollZoom':True
              })

# Change the bar mode
fig.update_layout(barmode='stack')
fig.show(config=config)

1 Like

Thank you. I suppose I will just have to add different code for the vertical lines.

1 Like

Since your case has numerical not categorical data, just use normal not absolute positioning for the text/annotations. Then it’s also correctly zoomable.