How to set color scaling?
12 ビュー (過去 30 日間)
古いコメントを表示
I would like to plot a surface or matrix with colors. How to set a linear scaling automatically by defining z1 to be color1 and z2 to be color2? z1 and z2 are general values not minz or maxz
0 件のコメント
回答 (1 件)
Mudambi Srivatsa
2016 年 9 月 27 日
編集済み: Mudambi Srivatsa
2016 年 9 月 27 日
I understand that you want to define a color scaling by assigning specific colors to Z values. Further, Z values are general but not min or max values. To do so, you can use 'colors' parameter and direct mapping scheme in "surf" function. For example, the following code snippet builds a color vector that assigns specific colors to the Z values.
[X,Y,Z] = peaks(30);
figure
cmap = [1 0 0; 1 1 0; 0 1 0];
colormap(cmap);
crange = 1;
colors = zeros(size(Z));
colors(Z <= -crange) = 1; % red (1)
colors(Z > -crange & Z < crange) = 2; % yellow (2)
colors(Z >= crange) = 3; % green (3)
surf(X,Y,Z, colors, 'CDataMapping','direct');
I assign the colors based on Z values using a range. In general, you can build your color vector manually or programmatically to assign colors that suit your needs.
Direct mapping uses the color data directly as indices into the colormap. For example, a value of 1 points to the first color in the colormap, a value of 2 points to the second color, and so on. If the color data is noninteger, MATLAB rounds it toward zero. Values greater than the number of colors in the colormap are set equal to the last color in the colormap (i.e., the number length(colormap)). Values less than one are set to one.
For more information on coloring surface plots, refer to the following documentation page:
https://www.mathworks.com/help/matlab/visualize/coloring-mesh-and-surface-plots.html
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!