[英]Plotly table cell color depending on cell data
大家好,我能得到任何可能的幫助嗎? 我正在嘗試根據對我的功能的回答對單元格顏色進行編碼。
b = df['Supertrend']
a = b[-1]
def main(a):
if a !=True:
return 'Bearish'
else:
return 'Bullish'
poes = main(a)
j = d1['Supertrend']
k = j[-1]
def main(k):
if k!= True:
return 'Bearish'
else:
return 'Bullish'
doos = main(k)
l = d15['Supertrend']
m = l[-1]
def main(m):
if m!= True:
return 'Bearish'
else:
return 'Bullish'
naai = main(m)
n = d1h['Supertrend']
o = n[-1]
def main(o):
if o!= True:
return 'Bearish'
else:
return 'Bullish'
tiet = main(o)
q = d1d['Supertrend']
p = q[-1]
def main(p):
if p!= True:
return 'Bearish'
else:
return 'Bullish'
kak = main(p)
TF = ['1 Minute', '5 Minutes', '15 Minutes', '1 Hour', 'Daily']
BB = [doos, poes, naai, tiet, kak]
fig = go.Figure(data=[go.Table(
header=dict(values=[['<b>Timeframe</b>'], ['<b>Bullish/Bearish</b>']],
line_color='black',
fill_color='black',
align='center',
height= 40,
font=dict(color='white', size=15)),
所以我想這是我需要幫助的地方。 規定如果 function 輸出看跌,則單元格必須為紅色,如果輸出看漲,則應為綠色
cells=dict(values=[TF,BB],
line_color='darkslategray',
fill = dict(color=['black',
我嘗試了下面的第一個但並沒有真正起作用
['#ff2d5d' if BB == str('Bearish') else '#04b29b']]),
font=dict(color='white', size=12),
height = 30,
align='center'))
])
fig.update_layout(width=500, height=450)
fig.show()
由於無法在列表中寫入if語句,因此可以預先創建一個顏色列表並指定它以對單元格進行顏色編碼。
TF = ['1 Minute', '5 Minutes', '15 Minutes', '1 Hour', 'Daily']
BB = [doos, poes, naai, tiet, kak]
colors = ['#ff2d5d' if c == 'Bearish' else '#04b29b' for c in BB]
print(colors)
fig = go.Figure(data=[go.Table(
header=dict(values=[['<b>Timeframe</b>'], ['<b>Bullish/Bearish</b>']],
line_color='black',
fill_color='black',
align='center',
height= 40,
font=dict(color='white', size=15)),
cells=dict(values=[TF,BB],
line_color='darkslategray',
fill = dict(color=['black',colors]),
font=dict(color='white', size=12),
height = 30,
align='center'))
])
fig.update_layout(width=500, height=450)
fig.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.