hello,
How can I format the y tick labels in e-notation? (note: I entered those exact labels as numbers in the form I want them to appear) but I still want them to appear in e-notation. Is there a way to do this when I edit the figure properties?
Thanks

 Respuesta aceptada

Sara
Sara el 6 de Mayo de 2014

0 votos

If you want to change the format of the y-axis:
y = get(gca,'ytick');
yy = cell(numel(y),1);
for i = 1:numel(y)
yy{i}=sprintf('%10.3e',y(i)); %%CHOOSE PRECISION
end
set(gca,'yticklabel',yy)

16 comentarios

Seldeeno
Seldeeno el 8 de Mayo de 2014
Thanks...but how can I use the "10^x" notation instead?
Sara
Sara el 8 de Mayo de 2014
You can't automatically. You'll have to replace the ticks with the text command. This may do it for you:
Seldeeno
Seldeeno el 8 de Mayo de 2014
This is very complicated for non-programmers. All I need is just how to print on the y-scale, values like 10^-20, 10^10 and so on
Thanks
Sara
Sara el 8 de Mayo de 2014
Are you using plot or semilogy or loglog to plot your data?
Seldeeno
Seldeeno el 8 de Mayo de 2014
I am using plot
Sara
Sara el 8 de Mayo de 2014
can you attach a sample of data or a plot of your data?
Seldeeno
Seldeeno el 8 de Mayo de 2014
This is the snippet I have. In this part, the data might take values that go from 10^-10 to 10^4 and I want the ytick to show such scale (although the code below is been uniformed).
clc
clear
axis([0 6 0 9])
grid on
hold on
% Initially, the list of points is empty.
xy = [];
n = 0;
% Loop, picking up the points.
disp('Left mouse button picks points.')
disp('Right mouse button picks last point.')
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
plot(xi,yi,'ro');xx(n+1)=xi;yy(n+1)=yi;
n = n+1;
xy(:,n) = [xi;yi];
end
% Interpolate with a spline curve and finer spacing.
t = 1:n;
ts = 1: 0.1: n;
xys = spline(t,xy,ts);
% Plot the interpolated curve.
plot(xys(1,:),xys(2,:),'b-');
hold off
Sara
Sara el 8 de Mayo de 2014
The issue is that if you use "plot" and the data range is that large, you won't see anything 1 or 2 order of magnitude lower that the maximum value. Try adding at the end and see if it solves your problem:
y = get(gca,'ytick');
tick2text(gca,'axis','y','convert',1,'yformat',@(y)sprintf('%.0f%s10^%.0f',y ./ 10.^floor(log10(y)),char(215),floor(log10(y))))
you need to download tick2text
Seldeeno
Seldeeno el 8 de Mayo de 2014
I thank you for your continuous help. My last question is that, for one of the figures, I want to show how data is behaving even on a small scale. Now I can normalize data but I want to enforce placing just two values on the y-axis: Just 10^-5 and 10^-1. How can I do this using your last hint?
Sara
Sara el 8 de Mayo de 2014
It needs to be modified for negative numbers so that you have something like 10^-^number. otherwise the number won't be at the exponent. Is that clear enough?
Seldeeno
Seldeeno el 8 de Mayo de 2014
forgive me for asking more, but as a non-programmer, I thought it would be easy (although tricky) to have such thing possible. What thing do I need to modify?
Thanks
Sara
Sara el 8 de Mayo de 2014
This will work only if your y axis is always < 1:
tick2text(gca,'axis','y','convert',1,'yformat',@(y)sprintf('%.0f%s10^-^%.0f',y ./ 10.^floor(log10(y)),char(215),-floor(log10(y))))
Seldeeno
Seldeeno el 8 de Mayo de 2014
Probably you didnt get my point, as all I wanted was to force that I print on the y-axis just two values like: 10^0 and 10^5 (just as ytick). Can I just do this?
Seldeeno
Seldeeno el 8 de Mayo de 2014
I made a progress with this code, but why are the yticks it overlapping the y-axis?
ax = subplot(1,1,1);
plot(x,y);
title('Modified tick marks');
set(ax, 'ylim', [0 9]);
tick2text(gca,'axis','y','convert',1,'yformat',@(y)sprintf('10^%.0f',y))
hx = getappdata(ax, 'YTickText');
set(hx, 'Rotation', 0, 'fontsize', 8, 'horiz', 'left');
Sara
Sara el 9 de Mayo de 2014
It's the:
'horiz', 'left'
command, try taking it away. Note, you may want to do:
set(gca,'fontsize',8)
so that all the ticks are of the same size.
Seldeeno
Seldeeno el 9 de Mayo de 2014
Sara, you are great. Thank you for your help :)

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 6 de Mayo de 2014

Comentada:

el 9 de Mayo de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by