我想用圆开放标记绘制“线条+标记”图,而不让线条穿过它。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
提交
取消