[英]bubble chart: how to change names and range of a tile, and the layout of the plot
[英]How to color a imshow chart based on a custom range
我正在制作一個用作熱圖的圖表,但我想將特定顏色設置為 x 和 x+0.05 之間的值,而不是“傳統”色標;
下圖是一個很好的視覺示例,可以說明我想做什么:
我嘗試了一些方法來做到這一點,但沒有一種方法奏效。
下面是一個MWE
import pandas as pd
import plotly.express as px
dict_vals = [
{"user1": None, "user2": 0.906, "user3": 0.842},
{"user1": 0.906, "user2": None, "user3": 0.527},
{"user1": 0.842, "user2": 0.527, "user3": None},
]
matrix_df=pd.DataFrame.from_dict(dict_vals)
fig = px.imshow(
matrix_df,
x=matrix_df.columns,
y=matrix_df.columns,
zmin=0.75,
zmax=0.95,
text_auto=True,
aspect="auto"
)
colors = [
"rgb(214, 11, 67)",
"rgb(255, 107, 0)",
"rgb(255, 201, 77)",
"rgb(168, 227, 0)",
"rgb(65, 175, 26)",
]
fig.update_coloraxes(
showscale=False,
colorscale=[
(0.0, colors[0]),
(0.8, colors[1]),
(0.85, colors[2]),
(0.9, colors[3]),
(0.95, colors[4]),
(1, colors[4]),
],
)
如果您對如何解決此問題有任何參考,我將不勝感激
我找到了一種方法來做我正在尋找的事情
import pandas as pd
import plotly.express as px
import numpy as np
dict_vals = [
{"user1": None, "user2": 0.906, "user3": 0.842},
{"user1": 0.906, "user2": None, "user3": 0.527},
{"user1": 0.842, "user2": 0.527, "user3": None},
]
matrix_df=pd.DataFrame.from_dict(dict_vals)
color_list=[[0, colors[0]],
[0.80, colors[0]],
[0.80, colors[1]],
[0.85, colors[1]],
[0.85, colors[2]],
[0.90, colors[2]],
[0.90, colors[3]],
[0.95, colors[3]],
[0.95, colors[4]],
[1.00, colors[4]]]
fig = px.imshow(
matrix_df.values,
x=matrix_df.columns,
y=matrix_df.columns,
zmin=0,
zmax=1,
text_auto=True,
aspect="auto",
color_continuous_scale=color_list
)
fig.update_coloraxes(showscale=True)
我希望它可以幫助將來的人。
問候,萊昂納多
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.