不确定是否可以在 pandas Styler 对象的框架下将 matplotlib 的DivergingNorm 用于颜色图。举个例子:
import pandas as pd
import matplotlib.cm
# retrieve red-yellow-green diverging color map
cmap = matplotlib.cm.get_cmap('RdYlGn')
# create sample pd.DataFrame
ix = pd.date_range(start=pd.Timestamp(2020, 1, 1), periods=4)
df = pd.DataFrame(index=ix, columns=['D/D CHANGE'], data=[-1, 0, 2, 5])
df.style.background_gradient(cmap=cmap)
理想情况下,只有负(正)值会显示为红色(绿色)。