[英]Visualizing a table according to its values
import pandas as pd
df = pd.DataFrame({'Hue value': [66.7, 0.42, 335.7, 77.9],
'Green value': [41.6, 4.23, 147.7, 37.3],
'Temperature': [39.9, 28.1, 41.8, 29.8]
})
print(df)
Hue value Green value Temperature
0 66.70 41.60 39.9
1 0.42 4.23 28.1
2 335.70 147.70 41.8
3 77.90 37.30 29.8
import seaborn as sns
cm = sns.light_palette("orange", as_cmap=True)
df.style.background_gradient(cmap=cm)
Styler
object 适用于整个 DataFrame,因此您可能需要应用并呈现每一列。
而描述温度的颜色通常是红色,因为热与红色有关。 有多种红色可供尝试,例如“深红色”、“番茄”、“印度红”、“火砖”、“栗色”等。请参阅此处了解各种颜色选项: https://matplotlib.org/stable /图库/颜色/named_colors.html
df[['Temperature']].style.background_gradient(cmap=sns.light_palette("red", as_cmap=True))
df[['Hue value']].style.background_gradient(cmap=sns.light_palette("magenta", as_cmap=True))
df[['Green value']].style.background_gradient(cmap=sns.light_palette("lime", as_cmap=True))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.