Log scaling of colors/colorbar for pcolor plot

  • Follow


I'm doing a pcolor plot where the Z values range from 0 to 40, but with nearly all the points below being less than 1.  I'm wondering if there is a way I can adjust the plot in such a way that my colorbar is scaled logarithmically rather than linearly.  Instead of [0 5 10 15 20 25 30 35 40] it would be [.0000001 .000001 .00001 .0001 .001 .01 .1 1 10 100].  Does anyone know if this is even possible and if so how it would be done?
0
Reply Matt 11/5/2010 6:03:04 PM

"Matt Spevak" <matt.remove.this.spevak@gmail.com> wrote in message <ib1gso$469$1@fred.mathworks.com>...
> I'm doing a pcolor plot where the Z values range from 0 to 40, but with nearly all the points below being less than 1.  I'm wondering if there is a way I can adjust the plot in such a way that my colorbar is scaled logarithmically rather than linearly.  Instead of [0 5 10 15 20 25 30 35 40] it would be [.0000001 .000001 .00001 .0001 .001 .01 .1 1 10 100].  Does anyone know if this is even possible and if so how it would be done?

You might want to read this link:

http://www.mathworks.com/support/solutions/en/data/1-16X5V/?solution=1-16X5V
0
Reply someone 11/5/2010 6:14:04 PM


perfect....thanks sum1

"someone" <someone@somewhere.net> wrote in message <ib1hhc$gbe$1@fred.mathworks.com>...
> "Matt Spevak" <matt.remove.this.spevak@gmail.com> wrote in message <ib1gso$469$1@fred.mathworks.com>...
> > I'm doing a pcolor plot where the Z values range from 0 to 40, but with nearly all the points below being less than 1.  I'm wondering if there is a way I can adjust the plot in such a way that my colorbar is scaled logarithmically rather than linearly.  Instead of [0 5 10 15 20 25 30 35 40] it would be [.0000001 .000001 .00001 .0001 .001 .01 .1 1 10 100].  Does anyone know if this is even possible and if so how it would be done?
> 
> You might want to read this link:
> 
> http://www.mathworks.com/support/solutions/en/data/1-16X5V/?solution=1-16X5V
0
Reply Matt 11/5/2010 9:00:08 PM

errr....that wasn't actually what I was looking for, but did look promising at first.  I need to change the actual colormapping in the plot.  The code in the link above only moved the tick marks and labels around.  I have lots of values from 10^-20 - 1 and very few outside that range.  I can save the results as a csv and bring them into GIS to plot with a log scale there, but would like to be able to do this in matlab to streamline the process.  Any ideas?
0
Reply Matt 11/5/2010 11:52:04 PM

Matt Spevak:
Just get the linear colormap you want to use, for example autumn, jet,
gray, hot, whatever, then use interp1 to interpolate it along a
different spacing, then apply the new colormap with the colormap()
function.
0
Reply ImageAnalyst 11/6/2010 12:24:42 AM

Okay, okay.  I know your next question is going to be "I don't know
how to do that, can you show me every step of the way in explicit,
gory detail?"

So here it is:
(Some long lines may get split into two by the newsreader.  If so,
join them to avoid syntax errors.)


clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
imtool close all;  % Close all imtool figures.
clear;  % Erase all existing variables.
workspace;  % Make sure the workspace panel is showing.
fontSize = 20;

% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010a\toolbox\images\imdemos';
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);

% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Image with linear "jet" colormap', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

% Apply a colormap
cmap = jet(256);
colormap(cmap);

% Get the individual colormaps, just for fun.
redMap = cmap(:,1);
greenMap = cmap(:,2);
blueMap = cmap(:, 3);

% Display the colorband maps, again just for fun.
subplot(2,2,2);
plot(redMap);
title('Red Map', 'FontSize', fontSize);
subplot(2,2,3);
plot(greenMap);
title('Green Map', 'FontSize', fontSize);
subplot(2,2,4);
plot(blueMap);
title('Blue Map', 'FontSize', fontSize);

figure;
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

% Construct the new colormaps with the new spacing.
% y = logspace(a,b,n) generates n points between decades 10^a and
10^b.
newX = logspace(0, log10(256), 256);
logRedMap = interp1(1:256, redMap, newX);
logGreenMap = interp1(1:256, greenMap, newX);
logBlueMap = interp1(1:256, blueMap, newX);

% Display the new colormaps
subplot(2,2,2);
plot(logRedMap);
title('Red Map', 'FontSize', fontSize);
subplot(2,2,3);
plot(logGreenMap);
title('Green Map', 'FontSize', fontSize);
subplot(2,2,4);
plot(logBlueMap);
title('Blue Map', 'FontSize', fontSize);

% Display the image again.
subplot(2,2,1);
imshow(grayImage, []);
title('Image with log colormap', 'FontSize', fontSize);

% Apply the new colormap to the gray scale image.
logMap = [logRedMap; logGreenMap; logBlueMap]';
colormap(logMap);
1
Reply ImageAnalyst 11/6/2010 12:51:47 AM

Of course you could also transform the image you're displaying to get
the same effect.

clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
imtool close all;  % Close all imtool figures.
clear;  % Erase all existing variables.
workspace;  % Make sure the workspace panel is showing.
fontSize = 20;

% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010a\toolbox\images\imdemos';
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Display the original gray scale image.
imshow(grayImage, []);
title('Image with linear "jet" colormap', 'FontSize', fontSize);

% Apply a colormap
cmap = jet(256);
colormap(cmap);
colorbar;

figure;
% Display the original gray scale image.
imshow(10.^(double(grayImage)/255), []);
title('10 .^ Image with linear "jet" colormap', 'FontSize', fontSize);

% Apply a colormap
colormap(cmap);
colorbar;

figure;
% Display the original gray scale image.
imshow(log10(double(grayImage)), []);
title('Log(Image) with linear "jet" colormap', 'FontSize', fontSize);

% Apply a colormap
colormap(cmap);
colorbar;


0
Reply ImageAnalyst 11/6/2010 2:38:26 AM

6 Replies
1667 Views

(page loaded in 0.096 seconds)

Similiar Articles:













7/20/2012 5:36:41 AM


Reply: