Plotly Express在多行的图上设置特定行的宽度
我正在尝试使用plotly.express使“关闭”线更宽。我尝试了有条件的语句或添加跟踪的各种选项,但似乎没有任何作用。
fig.for_each_trace(
lambda trace: trace.update(line=dict(color="Black", width=3)) if trace.name == "Close" else ()
这是代码:
import plotly.express as px
ticker = 'TSLA'
colours = ['steelblue', 'tan', 'black', 'red', 'green']
fig = px.line(df.tail(150), x=df.tail(150).index, y=['middle_band', 'SMA_200',
'upper_band', 'lower_band','Close'], title=f'{ticker}',
color_discrete_sequence=colours, width=800, height=600)
fig.update_traces(textfont_size=12, showlegend=True)
fig.update_layout(legend=dict(
yanchor="top",
y=0.9,
xanchor="left",
x=0.02
))
fig.update_xaxes(title_text='Price evolution over time', title_font = {"size": 16},)
fig.update_yaxes(title_text='Price', tickprefix="$")
fig.show()
一如既往,欢迎任何帮助。
I'm trying to make the 'Close' line wider than the others using plotly.express. I tried various options with a conditional statement, or adding a trace but nothing seems to work.
fig.for_each_trace(
lambda trace: trace.update(line=dict(color="Black", width=3)) if trace.name == "Close" else ()
This is the code:
import plotly.express as px
ticker = 'TSLA'
colours = ['steelblue', 'tan', 'black', 'red', 'green']
fig = px.line(df.tail(150), x=df.tail(150).index, y=['middle_band', 'SMA_200',
'upper_band', 'lower_band','Close'], title=f'{ticker}',
color_discrete_sequence=colours, width=800, height=600)
fig.update_traces(textfont_size=12, showlegend=True)
fig.update_layout(legend=dict(
yanchor="top",
y=0.9,
xanchor="left",
x=0.02
))
fig.update_xaxes(title_text='Price evolution over time', title_font = {"size": 16},)
fig.update_yaxes(title_text='Price', tickprefix="quot;)
fig.show()
As always, any help is welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在图show()之前添加此行,以增加第五行的宽度 -
fig ['data'] [4] ['line'] ['width'] = 5
,在0-4之间更改4个数字将使宽度 /厚度增加5(或您需要的任何数字)。我使用了随机数并绘制了您的代码。下面也是如此。plot
You can add this line just before fig.show() to increase the width of the 5th line -
fig['data'][4]['line']['width']=5
, changing the 4 to any number between 0-4 will increase the width / thickness by 5 (or any number you need). I have used random numbers and plotted your code. Same is below.Plot