title: How to set fixed color ranges with Seaborn heatmap?
body: <p>I am trying to make a heatmap with the Seaborn package, where I define my own color ranges. However, I cannot get the legend to show the values in a non-continous way. I would like the following color indication:</p>
  <p>0-0.001: green</p>
  <p>0.001-0.25: yellow</p>
  <p>0.25-0.50: orange</p>
  <p>0.50-0.75: red</p>
  <p>0.75-1.00: dark red</p>
  <p>But I get this:</p>
  <p><a href="https://i.stack.imgur.com/hbYFS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hbYFS.png" alt="enter image description here" /></a></p>
  <p>I suspect that the first range disturbs the picture, because it is smaller. However, I would like the legens &quot;boxes&quot; or area to be the same sizes. Is it therefore possible to have something like this or similar:</p>
  <p><a href="https://i.stack.imgur.com/wtZmQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wtZmQ.png" alt="enter image description here" /></a></p>
  <p>The code that I currently use is the one below. Any hint or suggestions would be highly appreciated. Thanks!</p>
  <pre><code>my_colors=['#02ab2e','gold','orange','red', 'darkred']
  
  
  grid_kws = {&quot;height_ratios&quot;: (.9, .025), &quot;hspace&quot;: .1}
  f, (ax, cbar_ax) = plt.subplots(2, gridspec_kw=grid_kws)
  ax = sns.heatmap(STEdata.iloc[:,3:13].reindex(ste_order_reg.sort_values().index, axis=0), 
                   yticklabels=2, ax=ax,
                   cmap = my_colors,
                   cbar_ax=cbar_ax, 
                   cbar_kws={&quot;orientation&quot;: &quot;horizontal&quot;})
  # sns.set(rc = {'figure.figsize':(8, 18)})
  
  colorbar = ax.collections[0].colorbar
  colorbar.set_ticks([0, 0, 0.25, 0.5, .75])
  colorbar.set_ticklabels(['0',']0-0.25]', ']0.25-0.50]',']0.50-0.75]', ']0.75-1.00]'])
  </code></pre>