我想用圓開放標記繪制“線條+標記”圖,而不讓線條穿過它。import plotly.graph_objects as goimport numpy as npx = np.arange(10)fig = go.Figure()fig.add_trace( go.Scatter( x=x, y=x**2, mode='lines+markers', line=dict(color='green'), marker_size=16, marker_symbol='circle-open' ))fig.update_layout( plot_bgcolor='white')fig.show()這會產生一條穿過開放標記的線。然后我嘗試在線條頂部添加背景色標記 - 但隨后在圖例中我只得到標記或線條,而不是兩者組合。有沒有辦法以這種方式獲得帶有標記和線條的圖例?fig = go.Figure()fig.add_trace( go.Scatter( x=x, y=x**2, mode='lines', line=dict(color='red'), showlegend=False, legendgroup='legend' ))fig.add_trace( go.Scatter( x=x, y=x**2, mode='markers', marker_color='white', # line=dict(color='green'), marker_size=12, marker_symbol='circle', marker_line=dict( width=3, color='red' ), legendgroup='legend' ))fig.update_layout( plot_bgcolor='white',)fig.show()
1 回答

郎朗坤
TA貢獻1921條經驗 獲得超9個贊
使用幾個屬性的正確組合應該可以幫助您實現這一目標:
marker_symbol='circle'
marker_color = 'white'
marker = dict(line = dict(color='green', width = 2))
陰謀
完整代碼:
import plotly.graph_objects as go
import numpy as np
x = np.arange(10)
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=x, y=x**2,
mode='lines+markers',
line=dict(color='green'),
marker_size=16,
marker_symbol='circle',
name = 'no line through this',
showlegend = True,
marker_color = 'white',
marker = dict(line = dict(color='green', width = 2))
)
)
fig.update_layout(
plot_bgcolor='white'
)
fig.show()
添加回答
舉報
0/150
提交
取消