2 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
在這里你應(yīng)該使用相同legendgroup的第一個(gè)痕跡并手動(dòng)設(shè)置相同的顏色。要隱藏第二個(gè)圖例,參數(shù)是showlegend=False。
import plotly.graph_objs as go
line_color=dict(color="blue")
layout1= go.Layout(title=go.layout.Title(text="A graph",x=0.5),
xaxis={'title':'x[m]'},
yaxis={'title':'y[m]','range':[-10,10]})
point_plot=[
go.Scatter(x=[3,4],
y=[1,2],
name="V0",
legendgroup="V0",
line=line_color),
go.Scatter(x=[1,2],
y=[1,1],
name="V0",
legendgroup="V0",
line=line_color,
showlegend=False),
go.Scatter(x=[5,6],
y=[2,3],
name="GT")]
go.Figure(data=point_plot, layout=layout1).show()

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以將兩個(gè)V0段組合成一個(gè)散點(diǎn)圖,并添加一個(gè)額外的點(diǎn)np.nan來(lái)拆分兩個(gè)段值,如下所示:
import plotly.graph_objs as go
import numpy as np
layout1= go.Layout(title=go.layout.Title(text="A graph",x=0.5),
xaxis={'title':'x[m]'},
yaxis={'title':'y[m]','range':[-10,10]})
point_plot=[
go.Scatter(x=[1,2,3,3,4],y=[1,1,np.nan, 1,2],name="V0"),
go.Scatter(x=[5,6],y=[2,3],name="GT")
]
go.Figure(data=point_plot, layout=layout1).show()
添加回答
舉報(bào)