I have checked the documentation, but I have not found an answer to my question.
This code comes from Plotly (link here) and allows to create a plot with two Y axis from two different data sets:
JavaScript
x
31
31
1
import plotly.graph_objects as go
2
from plotly.subplots import make_subplots
3
4
# Create figure with secondary y-axis
5
fig = make_subplots(specs=[[{"secondary_y": True}]])
6
7
# Add traces
8
fig.add_trace(
9
go.Scatter(x=[1, 2, 3], y=[40, 50, 60], name="yaxis data"),
10
secondary_y=False,
11
)
12
13
fig.add_trace(
14
go.Scatter(x=[2, 3, 4], y=[4, 5, 6], name="yaxis2 data"),
15
secondary_y=True,
16
)
17
18
# Add figure title
19
fig.update_layout(
20
title_text="Double Y Axis Example"
21
)
22
23
# Set x-axis title
24
fig.update_xaxes(title_text="xaxis title")
25
26
# Set y-axes titles
27
fig.update_yaxes(title_text="<b>primary</b> yaxis title", secondary_y=False)
28
fig.update_yaxes(title_text="<b>secondary</b> yaxis title", secondary_y=True)
29
30
fig.show()
31
Now. I want the data displayed in the second Y axis to be a scatter plot instead of a line. Is there a way to do it?
Thanks in advance.
Advertisement
Answer
You can set the mode
to be "markers"
instead of the default (which is "lines+markers"
):
JavaScript
1
5
1
fig.add_trace(
2
go.Scatter(x=[2, 3, 4], y=[4, 5, 6], name="yaxis2 data", mode="markers"),
3
secondary_y=True,
4
)
5