MATLAB Answers

Making two different color maps in 2014b

조회 수: 20(최근 30일)
John 2014년 11월 18일
댓글: Steven Lord 2016년 9월 23일
I'm trying to figure out how to use two different color maps in 2014b and use multiple color bars. Specifically I want to plot some image data and on top of that plot a set of contours.
Basically in the past I used freezecolors and cbfreeze. The same method behind freezecolors still works, changing the CData of your image to RGB values, but the colorbar is still a problem. CBfreeze doesn't seem to work any more because the colorbar objects are no long structs and now are specific objects.
I want to have separate colorbars for both the image data and contours but I can't seem to figure out the issue with the colorbars.
  댓글 수: 3
Adam 2014년 11월 19일
Wow, I'd never noticed R2014b snuck in that change. It's something I've wanted for quite a while, but must have missed in the changes listings!

댓글을 달려면 로그인하십시오.

채택된 답변

Sean de Wolski
Sean de Wolski 2014년 11월 18일
편집: Sean de Wolski 2014년 11월 18일
You can still use the freezecolors approach or one like I use in my meshCanopy function (same idea). You'll need to set the 'Limits' property of the colorbar to the range you want (and perhaps the tick/ticklabel etc.). For example:
I = imread('cameraman.tif');
n = 64;
h = colorbar;
%%Now compare
h.Limits = [256 256+n];

추가 답변(4개)

Nash Chu
Nash Chu 2016년 9월 23일
편집: Nash Chu 2016년 9월 23일
Actually you just need to add 'gca' when you define your colormap. like this:
pcolor(x,y,pxy);shading interp;
pcolor(x,y,pxy);shading interp;
  댓글 수: 1
Steven Lord
Steven Lord 2016년 9월 23일
I recommend avoiding using gca in your program files. When experimenting in the Command Window it's okay, but inside a function (and especially inside a GUI) it's too easy for the current axes to change without you realizing it. [As one example you create an axes intending to manipulate it using gca but before you can your user gets a little bored and clicks on a different axes.]
Instead, call subplot with an output argument (which will be the handle of the subplot axes) and pass that handle into colormap.
h = subplot(2, 1, 1);
% stuff
colormap(h, jet);

댓글을 달려면 로그인하십시오.

Jorge Ramirez
Jorge Ramirez 2014년 11월 19일
Thank you, Sean. However, the problem is how to add two different colorbars corresponding to the two different colormaps. Your example shows only one colorbar. I am attaching an example graph of what I mean. I produced the attached graph with Matlab 2013b using freezecolors and cbfreeze. However, as I said, cbfreeze does not work anylonger on Matlab 2014b.
Thank you.
  댓글 수: 2
John 2014년 11월 19일
Hi Sean,
I think you got it, thanks for the help! The only thing I'm going to have to watch out for is if the two data sources here are in the same range. It looks like you get around that by adding an offset to the data in the manifold right? I believe you can work around this by changing the labeling on the colorbar. I'll post a piece of example code if I get it working to show what I'm talking about.

댓글을 달려면 로그인하십시오.

Raul 2015년 2월 17일
Still isn't clear how to use two different colormaps. How do you change the colormap?

Chad Greene
Chad Greene 2015년 8월 16일
I made a solution to this for a problem I was working on. It's called newcolorbar.
  댓글 수: 1
Zhengwei Lai
Zhengwei Lai 2015년 12월 3일
thanks for your suggest

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by