admin管理员组文章数量:1134004
I would like to add a vline with default gride color. below code use lightgray
as vline color, how to make it the same as the default grid color?
import plotly.graph_objects as go
def main():
x = [1, 2, 3, 4, 5]
y = [10, 11, 12, 11, 9]
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y, mode='lines'))
fig.add_vline(x=2.5, line_width=.5, line_dash="solid", line_color="lightgray")
fig.update_layout(title='demo',template="plotly_dark",xaxis_title='x', yaxis_title='y')
fig.show()
return
I would like to add a vline with default gride color. below code use lightgray
as vline color, how to make it the same as the default grid color?
import plotly.graph_objects as go
def main():
x = [1, 2, 3, 4, 5]
y = [10, 11, 12, 11, 9]
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y, mode='lines'))
fig.add_vline(x=2.5, line_width=.5, line_dash="solid", line_color="lightgray")
fig.update_layout(title='demo',template="plotly_dark",xaxis_title='x', yaxis_title='y')
fig.show()
return
Share
Improve this question
asked Jan 7 at 22:52
lucky1928lucky1928
8,81110 gold badges52 silver badges105 bronze badges
1 Answer
Reset to default 3You can use fig.layout.template.layout.xaxis.linecolor
to get the vertical grid lines colors and fig.layout.template.layout.yaxis.linecolor
for the horizontal ones. It's usually the same color so it doesn't matter.
But to have it, the figure must first be updated with the new theme, so update_layout must be put first. So the code would like:
import plotly.graph_objects as go
def main():
x = [1, 2, 3, 4, 5]
y = [10, 11, 12, 11, 9]
fig = go.Figure()
fig.update_layout(
title="demo", template="plotly_dark", xaxis_title="x", yaxis_title="y"
)
grid_color = fig.layout.template.layout.xaxis.gridcolor
fig.add_trace(go.Scatter(x=x, y=y, mode="lines"))
fig.add_vline(x=2.5, line_width=0.5, line_dash="solid", line_color=grid_color)
fig.show()
return
本文标签: pythonplotlyadd vline with default grid colorStack Overflow
版权声明:本文标题:python - plotly - add vline with default grid color - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736770209a1952042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论