inserting colorbar in surf plots.

Hello Everyone,
I am using surf function to create a 3D shaded surface plot. I also define a variable C which is a 3 dimensional matrix. So if my number of rows and columns in Z is 155*125, my dimension of C matrix is 155*125*3.. I fill the color matrix C with RGB colors depending upon my criteria. The problem is when I want to display colorbar in my plot, I still get the standard RGB colorbar instead of the color matrix defined by me.
How can I modify the colorbar properties, so that it shows the actual colour being used in the plot.
thanks

 採用された回答

Sean de Wolski
Sean de Wolski 2013 年 8 月 20 日
編集済み: Sean de Wolski 2013 年 8 月 20 日

0 投票

Use the colormap function to set the figure's colormap to the one of your choice.
More per clarification:
%Emulate your C and Z
C = imresize(imread('peppers.png'),0.1);
Z = peaks(length(C));
Z = Z(1:size(C,1),1:ize(C,2));
%Surf it, facecolor is texturemap
surf(Z,C,'FaceColor','TextureMap');
%Extract 64 unique colors using rgb2ind, set it as the map and add colorbar
% For the peppers image this will look weird but if you have a good rgb
% image it will scale correctly.
[X, map] = rgb2ind(C,64);
colormap(map);
colorbar;

3 件のコメント

Ricky
Ricky 2013 年 8 月 20 日
actually sean I do not want to use a default colormap so I define my own RGB matrix which is of same size as my Z matrix. So if size of Z is m*n, size of C is m*n*3. For the surf function I give input as Z matirx and C matrix. I want to display this C matrix in colorbar.
Sean de Wolski
Sean de Wolski 2013 年 8 月 20 日
Ahh, okay. This is why a minimal working example always helps!
See more. In order to use a color bar, you will have to convert your rgb values to indices and extract the map - this is the purpose of rgb2ind.
Elizabeth Grace
Elizabeth Grace 2022 年 5 月 4 日
This gives me a colorbar that is out of order.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by