Specify RGB colour of contours with matplotlib

12,679

You should give a list with colors. If the list is 1 color long, it will use that color for all contours.

plt.contour(X, Y, Z, [0.1,0.2,0.3], colors = [(1.0,0.25,0.75)])
Share:
12,679
Rhysy
Author by

Rhysy

Updated on June 08, 2022

Comments

  • Rhysy
    Rhysy almost 2 years

    OK, I think this is probably simple but I've searched extensively and can't find anything. What I want to do is specify the precise RGB colour values of a contour line generated with matplotlib. I know that if I do something like :

    plt.contour(X,Y,Z,[0.1,0.2,0.3],colors='k')
    

    then I'll get three contour levels which are all black, or if I were to substitute 'w' in place of 'k' then the contours would all be white. That's fine, but what I need to do is something like this :

    plt.contour(X,Y,Z,[0.1,0.2,0.3],colors=(1.0,0.25,0.75)
    

    Where the colours not chosen from some in-built presets but have RGB (or RGBA) values precisely defined by me.

    Any ideas ?