I would like to use background gradients with the following DataFrame:
df = pd.DataFrame([{'Branch':'A', 'Date':datetime.datetime(2017, 1, 1), 'ratio':.3},
{'Branch':'B', 'Date':datetime.datetime(2017, 2, 1), 'ratio':.10},
{'Branch':'A', 'Date':datetime.datetime(2017, 2, 1), 'ratio':.40},
{'Branch':'B', 'Date':datetime.datetime(2017, 2, 1), 'ratio':.20},
{'Branch':'A', 'Date':datetime.datetime(2017, 3, 1), 'ratio':.80},
{'Branch':'B', 'Date':datetime.datetime(2017, 3, 1), 'ratio':.5}
])
df.set_index('Date', inplace=True)
tmp = df.groupby([pd.TimeGrouper('M'),'Branch']).sum()
tmp1 = tmp.unstack('Date').sort_index(axis=1, ascending=False)
Now I would like to colorize the various fields of the DataFrame using seaborn color paletts based on a fixed scale with minimum=0 and maximum=1.
I already tried to do it via:
import seaborn as sns
cm = sns.light_palette("green", as_cmap=True)
tmp1.style.background_gradient(cmap=cm, axis=1)
But unfortunately, this uses a dynamic range of the maximum and minimum values in the various rows and not the fixed scale of minimum=0 and maximum=1