auto format x axis

6 visualizaciones (últimos 30 días)
Jason
Jason el 19 de Feb. de 2014
Comentada: Jason el 20 de Feb. de 2014
In an attempt to change the x-axis format on a histogram (placed on a Axes object) from engineering format to just a number I have read that this can be done by using the "XTick" property of the axes.
I have images that have a greyscale upto 20500 and when I let matlab automatically control these it reverts to engineering mode. I only need 5 ticks and so was wondering how to use the following to change the ticks. They are by default set at 0, 0.2,0.4,0.6,1
XTck=get(handles.axes6,'XTick')
What i need is a way to take the current max value (20500) in this case and then work out the nearest multiple of 5 (that is larger than this value), and then modify the ticks by this.
e.g. in the above, if I made the max value 25000, then each one of my ticks will be 5000, so I could presumably change my ticks now by:
set(handles.axes6,'XTick', XTck*500) ??
Thanks for any comments Jason

Respuesta aceptada

Mischa Kim
Mischa Kim el 19 de Feb. de 2014
Editada: Mischa Kim el 19 de Feb. de 2014
Jason, this should do:
t = 0:4700;
y = rand(1,length(t)); % your data
t_lim = 1e3*ceil(t(end)/1e3); % get axis limit: 5000
t_ax = 0:t_lim;
n_int = 8; % define # of intervals
t_int = t_lim/n_int;
tt = t_ax(rem(t_ax,t_int)==0); % find tick locations
ttlab = num2cell(tt); % and generate tick labels
plot(t,y)
set(gca,'XTick', tt, 'XTickLabel', ttlab)
assuming that your axis limits are 1000s. If you don't even know the order of magnitude of data points a priori (e.g., there are only 5 data points) then you need some more logic (such as a log10() ) to get the scaling factor, which is currently set to 1e3=1000.
  3 comentarios
Mischa Kim
Mischa Kim el 19 de Feb. de 2014
See extended code above.
Jason
Jason el 20 de Feb. de 2014
For anyone else, if you use an axes to display the data on using GUIDE, then change the last line to:
set(handles.axes1,'XTick', tt,'XTickLabel',ttlab);
where in my case, my graph is drawn on axes1.

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Feb. de 2014
Maybe you need XtickLabel property

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by