MATLAB Answers

Chris F
0

How do I turn on (make visible) Major Tick Labels on a logarithmic Colorbar?

Asked by Chris F
on 18 May 2018
Latest activity Commented on by Chris F
on 18 May 2018

The tick marks themselves are set on the colorbar. However, only every other mark is labeled with the appropriate 10^x. How do I get these in-between labels to appear?

To be clear, my current work spans over ten of these labels. I can visually see eight major log tick marks on the color bar, plus the colorbar's min and max values. The lowest extreme is labeled (by default; I didn't make this happen) and moving up the colorbar only every other major tick is labeled. Only five labels exist on the colorbar, but I would like to see ten.

Preferably, I'd like to generalize the code such that if my numbers only go across six major log ticks or even fourteen log ticks that MATLAB will display all necessary major tick labels.

  4 Comments

Show 1 older comment

Sure. I've made up some numbers here so don't focus so much on the plot itself. But this does express the every other major tick label on the colorbar.

if true
x = [4e7, 5e11, 9e17];
y = [5e8, 4e11, 8e17];
z = [3e8, 6e11, 7e17];
average = (x+y+z)/3;
markersize = 99;
C = average;
color = C(:); %Vary color by value of average
scatter3(x,y,z,markersize,color,'Filled')
colorbar
set(gca,'ColorScale','log')
caxis([min(x),max(x)]); %set value range of colorbar
end

Sorry, I'm not able to run that code as there is no colorscale property connected to the axis (2017a). What version are you running?

Even the staff team seems a bit confused over this, (link)

Version 2018a. When I inserted the code that "if true, end" text wrapped itself around; maybe that's the issue running it?

I've attached a .jpg and .fig image of the plot. Hope that helps showing the every other tick labels.

Sign in to comment.

1 Answer

Answer by jonas
on 18 May 2018
Edited by jonas
on 18 May 2018
 Accepted Answer

So, finally finished installing latest release. Try setting the ticks manually and it should work. For the example given in the comments:

if true
x = [4e7, 5e11, 9e17];
y = [5e8, 4e11, 8e17];
z = [3e8, 6e11, 7e17];
average = (x+y+z)/3;
markersize = 99;
C = average;
color = C(:); %Vary color by value of average
scatter3(x,y,z,markersize,color,'Filled')
cb=colorbar
set(gca,'ColorScale','log')
caxis([min(x),max(x)]); %set value range of colorbar
end
set(cb,'ticks',10.^(8:20))

  1 Comment

That'll do it. I wrestled with those labels waaaay more than necessary... Thank you.

Sign in to comment.