Set colorbar ranges in 3d graphs

1 view (last 30 days)
Elria
Elria on 27 Sep 2012
Hey, I would like to create a three dimensional surface using this:
">> a=X
a =
Columns 1 through 8
0 50 100 150 200 250 300 350
Columns 9 through 16
400 450 500 550 600 650 700 750
Columns 17 through 21
800 850 900 950 1000
>> b=Y
b =
0
50
100
150
200
250
300
350
400
>> c=Z
c =
Columns 1 through 8
0 0 0 0 0 0 0 0
16 32 67 98 127 164 194 234
120 171 388 773 1086 1216 1770 2206
189 270 494 1978 2755 3134 5060 10469
133 166 183 348 647 937 1446 2304
192 162 154 113 161 189 266 482
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Columns 9 through 16
0 0 0 0 0 0 0 0
366 604 529 504 346 226 228 179
4027 11186 10276 5349 2560 1322 996 799
27413 76387 37949 15591 5804 2654 1803 1069
9844 24152 14772 4613 1777 849 459 290
1288 2623 1538 582 280 148 90 56
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Columns 17 through 21
0 0 0 0 0
108 94 79 0 0
646 476 612 0 0
884 858 722 0 0
266 215 139 0 0
48 48 31 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
>> surf(X,Y,Z)"
At the same time I would like to define that Z values < = 1803 will be shown with red color on the surface graph, 1803<Z<2755 yellow and Z > = 2755 green. How can I set the ranges of the colorbar in order to get this result? Thank you.

Accepted Answer

Sven
Sven on 28 Sep 2012
Hi Eleftheria,
You can use caxis() to set the colour limits (which is part of your problem... we'll get to the next bit).
Try this:
surf(X,Y,Z')
colorbar % This will show the colour axis
caxis([1803 2755])
But as you see, this just puts the limits to those ranges, but still has the gradiented colour map. Next, we need to set a new colour map:
colormap([1 0 0; 1 1 0; 0 1 0])
Did that do what you wanted?
  2 Comments
Elria
Elria on 28 Sep 2012
Edited: Elria on 28 Sep 2012
Hi Sven! Thank you once again but I still got some trouble. This way the colormap has lowest limit 1803 and max 2755 but what I really want is Z values from 0 to 1803 to be red, from 1803 to 2755 to be yellow and from 2755 to 76387 to be green. What I get is that: http://www.flickr.com/photos/87753025@N03/8031780155/ What can I do? Thanks!
Sven
Sven on 28 Sep 2012
Everything below the lowest limit in caxis([low high]) will be coloured as low, everything above the high limit will be coloured as high.
Everything between the limits will be distributed evenly from low to high. So, I guess what you need is to set the caxis lower limit low enough below 1803 so that the transition from red to yellow occurs at 1803. Try this:
lowToHigh = [1803 2755]
caxis(lowToHigh + [-1 1]*diff(lowToHigh))

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!