Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify RGB colour of contours with matplotlib

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 ?

like image 368
Rhysy Avatar asked Mar 17 '13 03:03

Rhysy


1 Answers

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)])
like image 113
Robbert Avatar answered Sep 23 '22 15:09

Robbert