在matplotlib中设置Colorbar颜色

2024-06-01 04:05:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

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() 

我得到了数字:enter image description here 但我想改变它的颜色,得到这样的图形enter image description here 我该如何设置颜色?


Tags: 代码importalphamatplotlib颜色asnpspecial