简体   繁体   中英

Visualizing a table according to its values

This is my Table:

这是我的数据

I can customize a column like so:

cm = sns.light_palette("green", as_cmap=True)
col1 = col1.dropna()
col1.style.background_gradient(cmap=cm)

which results in:

在此处输入图像描述

  1. I would like to color the cells according to their value, for example: In the Green value column, the RED and BLUE (RGB) values are 0 and I would like to have it colored according to the color scale of green (as well for the Hue column from the HSV scale). Is there a way to do it?

  2. Do you have any recommendation on which scale to use in order to visualize a temperature column?

Thanks a lot!

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)

在此处输入图像描述

The Styler object applies to the entire DataFrame, so you probably need to apply and present each column.

And the color to describe temperature is usually red, as heat is related to red. There are many variations of red to try out, for example 'darkred', 'tomato', 'indianred', 'firebrick', 'maroon', etc. Refer here for various color options: https://matplotlib.org/stable/gallery/color/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))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM