Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
howto plot 2 images with different colormaps

Subject: howto plot 2 images with different colormaps

From: Matthias Pospiech

Date: 19 Nov, 2010 16:23:40

Message: 1 of 5

This problem seams to be unsolved by mathworks for years.
And all tutorials for this do not work for me.

basically I plot twice with pcolor with two different colormaps

sp1 = subplot(1,2,1);
set(sp1,'Position',[0.01 0.1 0.35 0.9]);
colormap(sp1, cmapdataPhase);
hplot1 = pcolor(dataPhase); shading flat;

...
% freezeColors

sp2 = subplot(1,2,2);
set(sp2,'Position',[0.52 0.1 0.35 0.9]);
colormap(sp2, cmapdataIntensity);
hplot2 = pcolor(dataIntensity); shading flat;

This code applies the second colormap for both which is wrong.

There is the 'freezeColors' code which saves the colors
of the first plot, but does not save the colors in the colorbar.

There is also the script 'cbfreeze', but that makes the handle of the
colorbar invalid. And it reprints the colorbar at a complete wrong position.

This elimiantes almost all tutorials because the rely on both scripts.

I also tried to use one colormap with both plots using different parts
of them.
This is documented well here:
http://matlab.izmiran.ru/help/techdoc/creating_plots/axes_p18.html#12057

but this makes the colorbars show the complete colormap instead of the
part it is supposed to show.

So if there is any solution I would be very glad to know.
If it is possible to display two colorbars with complete different parts
of the current colormap that would be great, if so please let me know.

Otherwise I have to plot both in gray which is really what I do not
want, or I have to find a solution which does NOT rely on matlab...

Matthias

Subject: howto plot 2 images with different colormaps

From: Sean de

Date: 19 Nov, 2010 16:30:09

Message: 2 of 5

Matthias Pospiech <matthias79@gmx.de> wrote in message <ic68ag$n8u$1@newsserver.rrzn.uni-hannover.de>...
> This problem seams to be unsolved by mathworks for years.
> And all tutorials for this do not work for me.
>
> basically I plot twice with pcolor with two different colormaps
>
> sp1 = subplot(1,2,1);
> set(sp1,'Position',[0.01 0.1 0.35 0.9]);
> colormap(sp1, cmapdataPhase);
> hplot1 = pcolor(dataPhase); shading flat;
>
> ...
> % freezeColors
>
> sp2 = subplot(1,2,2);
> set(sp2,'Position',[0.52 0.1 0.35 0.9]);
> colormap(sp2, cmapdataIntensity);
> hplot2 = pcolor(dataIntensity); shading flat;
>
> This code applies the second colormap for both which is wrong.
>
> There is the 'freezeColors' code which saves the colors
> of the first plot, but does not save the colors in the colorbar.
>
> There is also the script 'cbfreeze', but that makes the handle of the
> colorbar invalid. And it reprints the colorbar at a complete wrong position.
>
> This elimiantes almost all tutorials because the rely on both scripts.
>
> I also tried to use one colormap with both plots using different parts
> of them.
> This is documented well here:
> http://matlab.izmiran.ru/help/techdoc/creating_plots/axes_p18.html#12057
>
> but this makes the colorbars show the complete colormap instead of the
> part it is supposed to show.
>
> So if there is any solution I would be very glad to know.
> If it is possible to display two colorbars with complete different parts
> of the current colormap that would be great, if so please let me know.
>
> Otherwise I have to plot both in gray which is really what I do not
> want, or I have to find a solution which does NOT rely on matlab...
>
> Matthias

I think this tech-note will greatly interest you:
http://www.mathworks.com/support/tech-notes/1200/1215.html

-Sean

Subject: howto plot 2 images with different colormaps

From: ImageAnalyst

Date: 19 Nov, 2010 16:34:59

Message: 3 of 5

On Nov 19, 11:23 am, Matthias Pospiech <matthia...@gmx.de> wrote:
> This problem seams to be unsolved by mathworks for years.
> And all tutorials for this do not work for me.
----------------------------------------------------------------------------------------------------------------
Are you saying the well known, official solution, given by Sean,
doesn't work for you?
(Because that's what I was going to suggest to you also.)
By the way, it's also in the FAQ:
http://matlab.wikia.com/wiki/FAQ#How_can_I_use_a_common_color_scale_among_several_images.3F

Subject: howto plot 2 images with different colormaps

From: Matthias Pospiech

Date: 19 Nov, 2010 16:52:45

Message: 4 of 5

Am 19.11.2010 17:34, schrieb ImageAnalyst:
> On Nov 19, 11:23 am, Matthias Pospiech<matthia...@gmx.de> wrote:
>> This problem seams to be unsolved by mathworks for years.
>> And all tutorials for this do not work for me.
> ----------------------------------------------------------------------------------------------------------------
> Are you saying the well known, official solution, given by Sean,
> doesn't work for you?
> (Because that's what I was going to suggest to you also.)
> By the way, it's also in the FAQ:
> http://matlab.wikia.com/wiki/FAQ#How_can_I_use_a_common_color_scale_among_several_images.3F

The site you suggest gives this code:

ax = findobj(gcf,'Type','axes');
set(ax,'CLim', [min(X(:)) max(X2(:))])

to set up the Limits for a solution using only one colormap.
The other code for that example is completely equivalent to what
I do.

I had set up the CLim using this code

CmLength = size(get(gcf,'Colormap'),1);% Colormap length
BeginSlot1 = 1; % Beginning slot
EndSlot1 = size(cmapdataPhase,1); % Ending slot
BeginSlot2 = EndSlot1+1;
EndSlot2 = CmLength;
CLim1 = get(sp1,'CLim');% CLim values for each axis
CLim2 = get(sp2,'CLim');

set(sp1,'CLim',newclim(1,100,CLim1(1),CLim1(2),CmLength))
set(sp2,'CLim',newclim(101,200,CLim2(1),CLim2(2),CmLength))
set(hcb1, 'CLim', get(sp1,'CLim'));
set(hcb2, 'CLim', get(sp2,'CLim'));

which sets up the limits, such that the plots are whith the correct
colors - but the colorbars are NOT correct.

If I use the code from the FAQ, everything is completely wrong!

colormap([cmapdataPhase;cmapdataIntensity]);
hfig1 = figure(1); clf;
sp1 = subplot(1,2,1);
set(sp1,'Position',[0.01 0.1 0.35 0.9]);
hplot1 = pcolor(dataPhase); shading flat;
hcb1 = colorbar('location','EastOutside');

sp2 = subplot(1,2,2);
set(sp2,'Position',[0.52 0.1 0.35 0.9]);
hplot2 = pcolor(dataIntensity); shading flat;
hcb2 = colorbar('location','EastOutside');

ax = findobj(gcf,'Type','axes');
set(ax,'CLim', [min(dataPhase(:)) max(dataIntensity(:))])

Now the whole colormap is applied to both plots and the whole
colormap is displayed in both plots.

And I do not even understand why this should work anyway.


So, yes the faq is wrong. And most examples/solutions do not
plot the colormap so any solution that works without a colormap
is not a complete solution...

Subject: howto plot 2 images with different colormaps

From: Sean de

Date: 19 Nov, 2010 17:00:23

Message: 5 of 5


> So, yes the faq is wrong. And most examples/solutions do not
> plot the colormap so any solution that works without a colormap
> is not a complete solution...

The tech-note I gave you does exactly what you want and provides an example.

I just used it yesterday in this thread:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/296725#797452
Perhaps that'll make the solution more clear.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us