Scientific notation colorbar

You could use colorbar‘s format parameter: import matplotlib.pyplot as plt import numpy as np import matplotlib.ticker as ticker img = np.random.randn(300,300) myplot = plt.imshow(img) def fmt(x, pos): a, b = ‘{:.2e}’.format(x).split(‘e’) b = int(b) return r’${} \times 10^{{{}}}$’.format(a, b) plt.colorbar(myplot, format=ticker.FuncFormatter(fmt)) plt.show()

Add alpha to an existing colormap

I’m not quite sure if this qualifies within “not knowing the inner structure of the colormap”, but perhaps something like this would work to add a linear alpha to an existing colormap? import numpy as np import matplotlib.pylab as pl from matplotlib.colors import ListedColormap # Random data data1 = np.random.random((4,4)) # Choose colormap cmap = … Read more

Set Colorbar Range

Using vmin and vmax forces the range for the colors. Here’s an example: import matplotlib as m import matplotlib.pyplot as plt import numpy as np cdict = { ‘red’ : ( (0.0, 0.25, .25), (0.02, .59, .59), (1., 1., 1.)), ‘green’: ( (0.0, 0.0, 0.0), (0.02, .45, .45), (1., .97, .97)), ‘blue’ : ( (0.0, … Read more

Standalone colorbar

You can create some dummy image and then hide it’s axe. Draw your colorbar in a customize Axes. import pylab as pl import numpy as np a = np.array([[0,1]]) pl.figure(figsize=(9, 1.5)) img = pl.imshow(a, cmap=”Blues”) pl.gca().set_visible(False) cax = pl.axes([0.1, 0.2, 0.8, 0.6]) pl.colorbar(orientation=”h”, cax=cax) pl.savefig(“colorbar.pdf”) the result:

Python/Matplotlib – Colorbar Range and Display Values

If I understand correctly what you want, I think this should do it: import numpy as np import matplotlib.pyplot as plt xi = np.array([0., 0.5, 1.0]) yi = np.array([0., 0.5, 1.0]) zi = np.array([[0., 1.0, 2.0], [0., 1.0, 2.0], [-0.1, 1.0, 2.0]]) v = np.linspace(-.1, 2.0, 15, endpoint=True) plt.contour(xi, yi, zi, v, linewidths=0.5, colors=”k”) plt.contourf(xi, … Read more

How can I create a standard colorbar for a series of plots in python

Not to steal @ianilis’s answer, but I wanted to add an example… There are multiple ways, but the simplest is just to specify the vmin and vmax kwargs to imshow. Alternately, you can make a matplotlib.cm.Colormap instance and specify it, but that’s more complicated than necessary for simple cases. Here’s a quick example with a … Read more

Scientific notation colorbar in matplotlib

You could use colorbar‘s format parameter: import matplotlib.pyplot as plt import numpy as np import matplotlib.ticker as ticker img = np.random.randn(300,300) myplot = plt.imshow(img) def fmt(x, pos): a, b = ‘{:.2e}’.format(x).split(‘e’) b = int(b) return r’${} \times 10^{{{}}}$’.format(a, b) plt.colorbar(myplot, format=ticker.FuncFormatter(fmt)) plt.show()