Can I adjust the scale of color bar in this seaborn heatmap?

Viewed 514

Here's a dictionary of data I'm trying to visualize:

SPEC1 = {-15.0: 0.2111724739193578,
 -14.487179487179487: 0.2394370325685465,
 -13.974358974358974: 0.28457460638442267,
 -13.461538461538462: 0.3060820977687277,
 -12.948717948717949: 0.27936658325947794,
 -12.435897435897436: 0.3264169114891287,
 -11.923076923076923: 0.33953701248120244,
 -11.41025641025641: 0.2543531073726878,
 -10.897435897435898: 0.2602820620861447,
 -10.384615384615385: 0.18850033433060892,
 -9.871794871794872: 0.16623948943981115,
 -9.35897435897436: 0.14385426255058673,
 -8.846153846153847: 0.13303206970028403,
 -8.333333333333334: 0.1738509378511952,
 -7.820512820512821: 0.12388968382768577,
 -7.307692307692308: 0.1453694114081282,
 -6.794871794871796: 0.14304888324965365,
 -6.282051282051283: 0.12446820153059315,
 -5.76923076923077: 0.11991471497857562,
 -5.256410256410257: 0.1555839620832947,
 -4.7435897435897445: 0.09174317021173255,
 -4.230769230769232: 0.14494865988744776,
 -3.717948717948719: 0.12053257742175423,
 -3.205128205128206: 0.15091820365530445,
 -2.6923076923076934: 0.16421715893800606,
 -2.1794871794871806: 0.15925544714381218,
 -1.6666666666666679: 0.2134519635533195,
 -1.153846153846155: 0.27845816943740104,
 -0.6410256410256423: 0.3104069080662138,
 -0.12820512820512953: 0.3576812987437953,
 0.38461538461538325: 0.40347578977116677,
 0.897435897435896: 0.39658696657701115,
 1.4102564102564088: 0.35957743409493415,
 1.9230769230769198: 0.36213347548006836,
 2.4358974358974343: 0.31049989028591496,
 2.948717948717949: 0.2678529728944247,
 3.46153846153846: 0.23923210055571248,
 3.974358974358971: 0.19244665788399845,
 4.4871794871794854: 0.1752279457602608,
 5.0: 0.17005550059340896}

And I used the seaborn.heatmap, here's the code and output:

import pandas as pd
import seaborn as sns
sns.set(rc={"figure.figsize":(12,1)})
df = pd.DataFrame(SPEC1, index=[0])
g = sns.heatmap(df, cmap="Greens", annot=False, fmt='g')
g.get_figure().savefig("heatmap.png")

enter image description here

I'll generate multiple bars like that, the values might be higher in the upcoming dictionaries, so I wonder if I could adjust the scale of the colorbar in my case, by that I mean I hope to set the darkest green color corresponds to '1' of the values (instead of '0.4') and the lightest color corresponds to '0'. Is there a way I can do that? Thanks for the help:)

1 Answers

Have you tried with vmin = 0 and vmax = 1?? I think that should work

Related