Plotly:如何仅使用一条迹线定义一个没有线穿过它的开放标记?
Plotly: How to define an open marker without a line going through it using only a single trace?
我想绘制一个带有圆圈开放标记的“线+标记”图,而不让线穿过它。
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-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()
使用一些属性的正确组合应该可以帮助您:
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()
我想绘制一个带有圆圈开放标记的“线+标记”图,而不让线穿过它。
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-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()
使用一些属性的正确组合应该可以帮助您:
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()