Is there any way to plot values that are exponent multiples of 10 as colorbar directly without having to take their log

1 view (last 30 days)
I was trying to plot 3 variables (depth, height, particles - these are attached as .mat files) with depth along the x axis, height along the y axis and particles as colors, using pcolor. This is the code which I used to obtain the plots (I used log10 for particles since their values were multiples of 1e10) and obtained the figure attached as log.jpg
d = load('depth.mat');
h = load('height.mat');
p = load('particles.mat');
depth = d.depth;
height = h.height;
particles = p.particles;
pcolor(depth, height, log10(particles))
bar = colorbar('XTickLabel', {'10^{5}', '10^{6}', '10^{7}'}, 'XTick',linspace(log10(1e5), log10(1e7),3));
caxis([log10(1e5) log10(1e7)])
But I really wanted to plot (depth, height, particles) and so I tried the following code:
d = load('depth.mat');
h = load('height.mat');
p = load('particles.mat');
depth = d.depth;
height = h.height;
particles = p.particles;
pcolor(depth, height, particles)
bar = colorbar('XTickLabel', {'10^{5}', '10^{6}', '10^{7}'}, 'XTick',linspace(1e5, 1e7, 3));
caxis([1e5 1e7])
This however gave me a different plot (attached as without_log.jpg). I am not sure why that occured since even if we take the log of the values and plot them, the so obtained values should still fall between the same color limits (for example, if the particle value of (say) 1e7*2.1232 corresponded to light red then log10(1e7*2.1232) should also correspond to light red since the color axis was also properly adjusted for both cases as shown in my code). Instead of getting the same plots, I am wondering why I have obtained the same plots.
Any feedback would be highly appreciated.
Thank you.

Accepted Answer

David Goodmanson
David Goodmanson on 7 Apr 2022
Hi Mathan,
The colorbars cover the same range in each case, but It's still apples and oranges. Consider the value 1e6 In log space, it's halfway between 1e5 and 1e7, so the color will be halfway up the colorbar on the using_log figure. But in linear space, 1e6 is (approximately) 10% of the way from 1e5 to 1e7, so you will only be 10% up on the colorbar on the without_log figure. So on the parts of the figure that aren't yellow, the without_log figure is darker.
  6 Comments
Mathan
Mathan on 9 Apr 2022
Edited: Mathan on 9 Apr 2022
Definitely! A range from 0 to 1e7 too would give the same plot as before (as in linear_ticks.jpg) except that the colorbar now shows ticks from 0 to 1e7.
Thank you David for the great discussion!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!