0

When I plot a contourf with uneven contour levels, the colorbar displays evenly-sized color areas. I'd like to adjust the heights of these color areas so that they scale with the steps in countourf levels. More generally, is there a simple way to adjust these heights arbitrarily?

Example code:

from pylab import *

figure(figsize = (4,3.3))

xi, yi = meshgrid(linspace(-1,1), linspace(-1,1))
zi = exp(-xi**2+yi)
zi -= zi.min()
zi /= zi.max()

contourf(xi, yi, zi, levels = [0, .2, .6, 1])
colorbar()
show()

mwe

Mathieu
  • 241
  • 1
  • 8
  • 1
    You might want to use `plt.colorbar(..., spacing='proportional')` – JohanC Oct 25 '20 at 18:53
  • Please note that nowadays `pylab` has been [replaced by `matplotlib.pyplot`](https://stackoverflow.com/questions/11469336/what-is-the-difference-between-pylab-and-pyplot). Also note that doing `import *` from pylab and from numpy can lead to very confusing behavior. It is highly recommend to `from matplotlib import pyplot as plt` and `import numpy as np` – JohanC Oct 25 '20 at 18:58

0 Answers0