Labeling Minor Tick Marks in Plots
45 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I am trying (without success) to find a way to automatically label the minor tick marks in a plot -- specifically, a semi-log-y plot. I thought that I would be able to do this using the get(gca,...) command to obtain the locations of the minor tick marks, and then the set(gca,'YTick',...) command to set the minor ticks as major ticks. However, I wasn't able to figure out how to obtain the locations of the minor ticks using the get(gca,...) command. Please let me know if you have a solution. An example code is shown below:
function label_minor_ticks()
figure
y = [0.4,0.5,0.8,1,1.5,2,4];
semilogy(y);
end
0 comentarios
Respuesta aceptada
Grzegorz Knor
el 6 de Oct. de 2011
Remove YMinorTicks, and add new YTicks:
y = [0.4,0.5,0.8,1,1.5,2,4];
semilogy(y);
set(gca,'yMinorTick','off')
yRange = get(gca,'ylim');
p = ceil(log(yRange) / log(10));%nextpow10
ticks = [];
for k=p(1):p(2)
if k==p(1)
ticks = [ticks yRange(1):10^(k-1):10^k];
elseif k==p(2)
ticks = [ticks 10^(k-1)+10^(k-1):10^(k-1):yRange(2)];
else
ticks = [ticks 10^(k-1)+10^(k-1):10^(k-1):10^(k-1)];
end
end
set(gca,'ytick',ticks(2:end-1))
This loop does not look good for me, but it works :)
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Axis Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!