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

조회 수: 1 (최근 30일)
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.

채택된 답변

David Goodmanson
David Goodmanson 2022년 4월 7일
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
David Goodmanson
David Goodmanson 2022년 4월 9일
Hi Mathan,
the colorbar looks pretty good to me. The only thing I can really find fault with is that the lower end is not marked .1, so it's hard to tell if the minimum value is 1e-5 or 0. On that note, it's probably better in linear scale to go from 0 to 1e7 rather than 1e5 to 1e7. And yes, the enitire range from 1e5 to 1e6 is squished into the narrow blue part of the colorbar, because that's what linear scale does.
Mathan
Mathan 2022년 4월 9일
편집: Mathan 2022년 4월 9일
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!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by