how to set the ticks in the colorbar to be automatic and as many as possible?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
i'm trying to use as many ticks in the colorbar doing so manualy lead to unexpected resault such as:

(in the attached image)
i used:
cbr=colorbar('fontsize',15);
set(cbr,'YTick',min(min(MAT)):max(max(MAT))/100:max(max(MAT)))
how can i still get as many ticks as possible but still keeping the data readable
1 comentario
Stephen23
el 2 de Sept. de 2014
Editada: Stephen23
el 2 de Sept. de 2014
If you are wanting to maximize the the number of tickmarks but keep them distinct, then number does not depend on the data range, but instead on the height of the colorbar and text fontsize (as Image Analyst described below).
To calculate this automatically take a look at the axes and text properties, as well as the commands get and set . It might also be useful to look at the default text fontsize.
If an automatic calculation is unjustifiably too much work, or is too intimidating, then you will have to set it manually.
Respuestas (1)
Image Analyst
el 1 de Sept. de 2014
I thing you might have just do trial and error. It depends on the font size and how many pixels are between the top of the bar and the bottom. Maybe if you can figure out the height of the colorbar in pixels and specify the fontsize in pixels, you might be able to calculate it. I don't have any code all ready to hand you though.
2 comentarios
Image Analyst
el 2 de Sept. de 2014
I don't know. I can't experiment with it anymore - gotta do something else now. Here is what I got so far. You can take over now.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
z = peaks(1000);
imshow(z, []);
colormap(jet(256));
hColorBar = colorbar('Units', 'pixels', 'FontSize', 35);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
position = get(hColorBar, 'Position')
% Get the tick numbers
allProperties = get(hColorBar) % Print out everything you can get to the command window.
tickLabels = get(hColorBar, 'YTickLabel')
tickNumbers = get(hColorBar, 'YTick')
numberOfLabels = length(tickLabels);
pixelsPerNumber = position(4) / numberOfLabels
message = sprintf('Your colorbar is %.1f pixels high\nand there are %d labels.\nYou can have %.1f vertical pixels per color bar tick label', ...
position(4), numberOfLabels, pixelsPerNumber);
uiwait(msgbox(message));
% Set fontsize in pixels
% set(hColorBar, 'FontSize', pixelsPerNumber);
Ver también
Categorías
Más información sobre Color and Styling en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!