Search code examples
matlabmatlab-figurecontourf

Using custom colormap on contourf


I have created a colourmap 'mycmap' which I want to use on every contourf in Matlab. How do this?

I have tried

[C,h]=contourf(Xrange,Y_range,capacity,14,'LineColor',mycmap');

but it doesn't work. My custom colour scale looks like:

mycmap =

0.9725    0.9725    0.9725
0.9442    0.9442    0.9442
0.9159    0.9159    0.9159
0.8876    0.8876    0.8876
0.8593    0.8593    0.8593
0.8310    0.8310    0.8310
0.8027    0.8027    0.8027
0.8002    0.8002    0.8002
0.7976    0.7976    0.7976
0.7950    0.7950    0.7950
0.7924    0.7924    0.7924
0.7204    0.7204    0.7204
0.6484    0.6484    0.6484
0.6484    0.6484    0.6484
0.6484    0.6484    0.6484
0.6329    0.6329    0.6329
0.6175    0.6175    0.6175
0.6021    0.6021    0.6021
0.5885    0.5885    0.5885
0.5750    0.5750    0.5750
0.5615    0.5615    0.5615
0.5480    0.5480    0.5480
0.5345    0.5345    0.5345
0.5210    0.5210    0.5210
0.5075    0.5075    0.5075
0.4940    0.4940    0.4940
0.4564    0.4564    0.4564
0.4188    0.4188    0.4188
0.4092    0.4092    0.4092
0.3995    0.3995    0.3995
0.3899    0.3899    0.3899
0.3802    0.3802    0.3802
0.3706    0.3706    0.3706
0.3609    0.3609    0.3609
0.3512    0.3512    0.3512
0.3416    0.3416    0.3416
0.3328    0.3328    0.3328
0.3239    0.3239    0.3239
0.3151    0.3151    0.3151
0.3063    0.3063    0.3063
0.2974    0.2974    0.2974
0.2886    0.2886    0.2886
0.2798    0.2798    0.2798
0.2771    0.2771    0.2771
0.2743    0.2743    0.2743
0.2716    0.2716    0.2716
0.2689    0.2689    0.2689
0.2661    0.2661    0.2661
0.2634    0.2634    0.2634
0.2607    0.2607    0.2607
0.2580    0.2580    0.2580
0.2552    0.2552    0.2552
0.2525    0.2525    0.2525
0.2498    0.2498    0.2498
0.2471    0.2471    0.2471
0.2196    0.2196    0.2196
0.1922    0.1922    0.1922
0.1647    0.1647    0.1647
0.1373    0.1373    0.1373
0.1098    0.1098    0.1098
0.0824    0.0824    0.0824
0.0549    0.0549    0.0549
0.0275    0.0275    0.0275
     0         0         0

Thanks for helping.


Solution

  • You could invoke the colour map after the plotting...

    [C,h]=contourf(Xrange,Y_range,capacity,14)
    colormap(mycmap);