Search code examples
pythoncolorbar

How to change colorbar using Matplotlib?


if I'm plotting a contour like this, how could I change the color bar for "jet" colour? Is it necessary to call a figure first?

plt.contourf(X,Y,Z)
plt.colorbar().set_label(label='values',size=12)
plt.grid(True)

Solution

  • You can supply a parameter to the contourf function:

    plt.contourf(X, Y, Z, cmap=plt.cm.jet)
    

    or

    plt.contourf(X, Y, Z, cmap='jet')