How to set contourf colors ?
Mostrar comentarios más antiguos
I use contour for plot three concentric isolines, now I would like to fill the area inside this isolines with a choosen color, for example heavy green, medium green and light green. How I can do it?
I tried with contourf and colormap but I'm not enought skilled for properly set the colors. This is my code:
data = fopen ( datafile,'r');
M = fscanf ( data , '%f', [128, 128]);
[x,y] = meshgrid(-gr:2*gr/127:gr);
contourf(x,y,M,[5000 1000 500]);
map = [0 0.6 0.2; 0 0.8 0.2; 0 1 0.2];
colormap (map);
Any helps?
Respuesta aceptada
Más respuestas (4)
Sean de Wolski
el 24 de Sept. de 2014
doc caxis
And a simple example:
contourf(magic(5),3);
caxis([0 25])
colormap(rand(3))
Dario
el 24 de Sept. de 2014
0 votos
1 comentario
Sean de Wolski
el 24 de Sept. de 2014
I used caxis([0 25]) because my example data ranged from 1:25.
You might want to use something like:
caxis([min(M(:)),max(M(:))])
to scale it to the range of your data
Dario
el 24 de Sept. de 2014
0 votos
7 comentarios
Kelly Kearney
el 24 de Sept. de 2014
Editada: Kelly Kearney
el 24 de Sept. de 2014
Well, I don't have your data; you'll have to attach your datafile if you want specifics. But here's an example with placeholder data. Note that you need to define one more contour level than number of colors, since the colors refer to the space between two contour lines.
[x,y,M] = peaks(50);
clev = [-5 -1 1 5];
map = [0 0.6 0.2; 0 0.8 0.2; 0 1 0.2];
contourfcmap(x,y,M,clev,map,[0 0 0], [1 1 1], 'eastoutside');
Dario
el 25 de Sept. de 2014
Kelly Kearney
el 25 de Sept. de 2014
Editada: Kelly Kearney
el 25 de Sept. de 2014
Yes, it should be fine in that version. Are you encountering problems? I've hit occasional issues where contourf creates some unexpected lines, but contourfcmap should throw an error stating this.
Dario
el 25 de Sept. de 2014
Kelly Kearney
el 26 de Sept. de 2014
Editada: Kelly Kearney
el 26 de Sept. de 2014
As I stated above, you need to provide one more contour line level than the number of colors. Right now, you've got 3 colors, and only 2 intervals to assign those to (500-1000 and 1000-5000). Based on your screenshot, I'm guessing you want the third color to fill in anything higher than 5000. In that case, pass 2 colors as the colormap, and the third as the hi input:
contourfcmap(x,y,Data,clev,cmap(1:2,:),[1 1 1],cmap(3,:));
Kelly Kearney
el 29 de Sept. de 2014
That will depend on which version of Matlab you're running, and whether you have the Mapping Toolbox (those two factors determine whether contourfcmap output is contourgroup objects or patch and line objects. Either way, the easiest would likely be to just add new contours on top and label those:
contourfcmap (x,y,Data, clev, cmap);
hold on;
[c,h] = contour(x,y,Data,clev, 'k');
clabel(c,h);
Categorías
Más información sobre Color and Styling en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
