jiangniao
jiangniao

Reputation: 135

Set Colorbar color in matplotlib

I have the following code:

import matplotlib.pyplot as plt
import numpy as np
from scipy import integrate, special
import pylab
def f(v,r):
    """ Initial function"""
    alpha = 0.2
    chi = 1/2*special.erf((r+1.2)/0.3)-1/2*special.erf((r-1.2)/0.3)
    return 4/(np.sqrt(2*np.pi*alpha))*chi*np.exp(-v**2/(2*alpha))


N_xi = 100

v = (np.arange(N_xi)*4/(N_xi - 1)-2)
r = (np.arange(N_xi)*4/(N_xi - 1)-2)
z = f(v.reshape(-1, 1), r.reshape(1, -1))

pylab.pcolor(v, r, z)

pylab.colorbar()

pylab.show() 

And I got the figure:enter image description here But I want to change the color of it, to get the figure like thisenter image description here How can I set the color?

Upvotes: 2

Views: 11601

Answers (1)

Suever
Suever

Reputation: 65430

You need to specify the jet colormap when creating the pcolor object

pylab.pcolor(v, r, z, cmap='jet')

That being said, the jet colormap isn't ideal for many situations so take care to choose an appropriate colormap.

enter image description here

Upvotes: 2

Related Questions