[英]How to control the color input of a Sunburst with plotly.graph_objects?
[英]How can i make some points of different color in last frame of plotly.graph_objects
fig = go.Figure()
f = []
hours = range(0, 60)
pts = [rd.randrange(11, 100, 13) for i in range(1, 61)]
for i in range(1, 61):
f.append(go.Frame(data=[go.Scatter(x=list(hours[1:61]), y=list(pts[:i]), name="PRB
Usage",line=dict(color="#1E90FF"),marker=dict(size=10,line=dict(width=3,color="yellow")))]))
fig.update(frames=f)
c = fig.to_html(config={'displayModeBar': False})
這里我的 animation 有 60 幀的聯合散點圖 plot,在完成 animation 之后我想改變那些大於 80 小於 20 的點的顏色
我嘗試在 fig.update(frames=f) 語句之后添加新的 plot 的 add_trace,但它顯示了 animation 完成之前
你的問題只有部分代碼,所以我用我的猜測彌補了不足。 如果要對 animation 的最后一個圖形添加特殊處理,請創建一個新的最終框架並替換已存在框架列表中的最后一個框架。 顏色條件指定在新的最后一幀中超出標准值的 colors 列表。
import plotly.graph_objects as go
import random as rd
f = []
hours = range(0, 60)
pts = [rd.randrange(11, 100, 13) for i in range(1, 61)]
data = [go.Scatter(x=[], y=[])]
layout = go.Layout(
xaxis=dict(range=[0,60], autorange=False),
yaxis=dict(range=[0,100], autorange=False),
title='Animation frames',
updatemenus=[dict(
type="buttons",
buttons=[dict(label="Play",
method="animate",
args=[None])])]
)
for i in range(1, 61):
f.append(go.Frame(data=[
go.Scatter(
mode='markers',
x=list(hours[:i]),
y=list(pts[:i]),
name="PRB Usage",
# line=dict(color="#1E90FF"),
marker=dict(size=10, color="blue")
)
]))
f[-1] = go.Frame(data=[go.Scatter(mode='markers', x=list(hours), y=pts, marker=dict(size=10, color=['red' if x >= 80 else 'blue' for x in pts]))])
fig = go.Figure(data=data, layout=layout, frames=f)
fig.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.