How to plot a 3D surface out of points, and set explicit colors for specific value ranges
Show older comments
I have matrices x, y, z, and s, which have dimensions 2500x1. I'm trying to make a surface plot out of x, y, z. I tried this:https://www.mathworks.com/matlabcentral/answers/384291-3d-surface-plot-out-of-points#answer_306637. But is it possible to set plot colors for specific value ranges of s (given in the table below)? Like by applying a colormap or something?

I have defined the colormap as follows:
map = [0 1 0;
0 1 1;
0 0 1;
0 0.5 1;
1 1 1;
1 1 0.5;
1 1 0;
1 0.5 0;
1 0 0];
colormap(map);
caxis([-1 1]);
As an example, I need the plot to look similar to this:

2 Comments
darova
on 14 Mar 2020
Your code looks correct. What is the problem?
Batyrkhan Tokmyrza
on 14 Mar 2020
Answers (2)
Ameer Hamza
on 14 Mar 2020
It is obvious from your image that you are not setting the limits of caxis properly. Your code
caxis([-1 1]);
but your image show that value vary in range [-4000, 4000]

Try
caxis([-4000 4000]);
4 Comments
Batyrkhan Tokmyrza
on 14 Mar 2020
Ameer Hamza
on 15 Mar 2020
Can you show your code? How is variable s being used?
Batyrkhan Tokmyrza
on 15 Mar 2020
Ameer Hamza
on 15 Mar 2020
Edited: Ameer Hamza
on 15 Mar 2020
The color is taken from the colormap according to whatever variable is on the z-axis and the value of CLim for the color axis. If you want the colormap to be linked to s, then you need to use s in place of z in your code.
What do the four columns of your dataset represent? Maybe that can help in determining how the s value can be used.
Walter Roberson
on 15 Mar 2020
Your map is wrong. You did not take into account that the first and last slots are half the size of the other slots.
map = [ 0 1 0 ; %-1 to -7/8 %green
0 1 1 ; %-7/8 to -6/8 %cyan
0 1 1 ; %-6/8 to -5/8
0 0 1 ; %-5/8 to -4/8 %blue
0 0 1 ; %-4/8 to -3/8
0 0.5 1 ; %-3/8 to -2/8 %pale blue
0 0.5 1 ; %-2/8 to -1/8
1 1 1 ; %-1/8 to 0 %white
1 1 1 ; %0 to +1/8
1 1 0.5; %+1/8 to +2/8 %pale yellow
1 1 0.5; %+2/8 to +3/8
1 1 0 ; %+3/8 to +4/8 %yellow
1 1 0 ; %+4/8 to +5/8
1 0.5 0 ; %+5/8 to +6/8 %orange
1 0.5 0 ; %+6/8 to +7/8
1 0 0 ]; %+7/8 to +1 %red
2 Comments
Batyrkhan Tokmyrza
on 15 Mar 2020
Ameer Hamza
on 15 Mar 2020
I provided the same solution to OP's other question here: https://www.mathworks.com/matlabcentral/answers/510757-how-to-set-explicit-contour-plot-colors-for-specific-value-ranges?s_tid=prof_contriblnk but here the issue seems to be about the limits of color axis.
Categories
Find more on Color and Styling 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!