情节:如何在指定条件的线图上显示不同的颜色/线段?
我正在尝试绘制基于特定条件的线颜色和线本身(即使用仪表盘或虚线)区分线颜色的线路图。 该图没有显示线条上的线/变化,但是当我徘徊在图表上以及传奇中时,我可以看到图颜色的颜色变化。
fig = px.line(df2, x=df2['Time_Stamp'], y=df2['Blob_1_Prob_48H'])
count = 0
for j, y in enumerate(df2.Blob_1_Prob_48H):
if count==0:
count +=1
fig.add_traces(go.Scatter(
x = [df2['Time_Stamp'][j]],
y = [df2['Blob_1_Prob_48H'][j]],
mode = "lines+markers",
name = "48H",
text= df2.Name,
hovertemplate="Prediction Percentage: %{y}<br>Date &Time: %{x}<br>Name: %{text}<extra></extra>"))
else:
if df2['Blob_1_Prob_48H'][j] < df2['Blob_1_Prob_48H'][j-1]:
fig.add_traces(go.Scatter(
x = [df2['Time_Stamp'][j]],
y = [df2['Blob_1_Prob_48H'][j]],
mode = 'lines',
name = "48H",
line = dict(color='red',width=5, dash='dot'),
text= df2.Name,
hovertemplate="Prediction Percentage: %{y}<br>Date &Time: %{x}<br>Name: %{text}<extra></extra>"))
fig.update_layout(title="ALEX(S)",xaxis_title='Date & time',yaxis_title='Blob percentage',yaxis_range=[0,105],showlegend=True,width=1200,
height=600)
fig.show()
I'm trying to plot a line chart that differentiates the line color and the line itself(i.e. using a dash or dotted lines) based on a specific condition.
The figure isn't showing the lines/change in line color but I could see the change in the color of data points on the plot when I hovered over the chart and also in the legend.
fig = px.line(df2, x=df2['Time_Stamp'], y=df2['Blob_1_Prob_48H'])
count = 0
for j, y in enumerate(df2.Blob_1_Prob_48H):
if count==0:
count +=1
fig.add_traces(go.Scatter(
x = [df2['Time_Stamp'][j]],
y = [df2['Blob_1_Prob_48H'][j]],
mode = "lines+markers",
name = "48H",
text= df2.Name,
hovertemplate="Prediction Percentage: %{y}<br>Date &Time: %{x}<br>Name: %{text}<extra></extra>"))
else:
if df2['Blob_1_Prob_48H'][j] < df2['Blob_1_Prob_48H'][j-1]:
fig.add_traces(go.Scatter(
x = [df2['Time_Stamp'][j]],
y = [df2['Blob_1_Prob_48H'][j]],
mode = 'lines',
name = "48H",
line = dict(color='red',width=5, dash='dot'),
text= df2.Name,
hovertemplate="Prediction Percentage: %{y}<br>Date &Time: %{x}<br>Name: %{text}<extra></extra>"))
fig.update_layout(title="ALEX(S)",xaxis_title='Date & time',yaxis_title='Blob percentage',yaxis_range=[0,105],showlegend=True,width=1200,
height=600)
fig.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然有更好的方法可以做到这一点,但是这是我将列表分为许多增加和减少曲线的代码,然后用不同的样式绘制它们:
输出:

如果您有大量数字,则应适应Numpy或Pandas。
There are certainly better ways to do this, but here is one code where I separate a list into many increasing and decreasing curves and then plot them with different styles:
Output:

If you have large amount of numbers, you should adapt to numpy or pandas, for example.