Making two different color maps in 2014b
이전 댓글 표시
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.
Thanks,
John
댓글 수: 3
Doug Hull
2014년 11월 18일
In R2014b MATLAB there is a colormap per axes, not just per figure. This solves lot of problems from the past. Since you are still using freezecolors to get two colormaps in the same axes, that is still fine.
The real question is getting two colorbars for the same axes, correct?
Can you post a typical firgure from before?
Jorge Ramirez
2014년 11월 18일
I have the same question/problem. I am attaching a figure of what I could do before 2014b using freezeColors and cbfreeze. However, cbfreeze does not seem to work in 2014b. Thank you.
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!
채택된 답변
추가 답변 (4개)
Actually you just need to add 'gca' when you define your colormap. like this:
figure
subplot(2,1,1)
pcolor(x,y,pxy);shading interp;
colormap(gca,jet);
colorbar;
subplot(2,1,2)
pcolor(x,y,pxy);shading interp;
colormap(gca,autumn);
colorbar;
댓글 수: 1
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
2014년 11월 19일
0 개 추천
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.
Jorge
댓글 수: 2
Sean de Wolski
2014년 11월 19일
편집: Sean de Wolski
2014년 11월 19일
In that case just call colorbar twice and change the position as necessary:
I = imread('cameraman.tif');
meshCanopy(I,stdfilt(I),parula(64),80);
ax = gca;
h = colorbar('peer',ax);
h.Limits = [1 256];
h.Ticks = [];
h.Position(1) = h.Position(1)-0.1;
h = colorbar('peer',ax);
h.Limits = [256 256+64];
h.Ticks = [];

Raul
2015년 2월 17일
0 개 추천
Still isn't clear how to use two different colormaps. How do you change the colormap?
Chad Greene
2015년 8월 16일
0 개 추천
댓글 수: 2
Zhengwei Lai
2015년 12월 3일
thanks for your suggest
Serena
2025년 3월 4일
I am trying to create a surface plot which uses two different inputs so two different colorbars etc.
I have tried freezecolors but this function keeps the different colormaps for plots but not the colorbars.
I tried your function but when I ran the newcolorbar command the data in the plot dissappeared, and I had both colormaps with an empty plot. Is there a command I must add to fix this?
Thanks
카테고리
도움말 센터 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
