Borrar filtros
Borrar filtros

Pre-determine plot ranges?

2 visualizaciones (últimos 30 días)
Chris
Chris el 21 de Ag. de 2019
Comentada: Chris el 23 de Ag. de 2019
Given two vectors of the same length is there a way to determine the axes ranges that would result if the data were plotted without plotting the data?
I am looking to update xlim and ylim manually after the plotted data is changed* but with out relying on the automatic resizing as there are other things plotted that I dont want to be used in determining the plot ranges. Also I would rather not redraw the entire figure with just the modified data then redraw the larger thing.
(plotted data is changed*: I am manipulating the XData and YData parameter of plotted data directly with a handle.)

Respuesta aceptada

Adam Danz
Adam Danz el 21 de Ag. de 2019
Editada: Adam Danz el 21 de Ag. de 2019
If vector1 and vector1 are the x and y values to be plotted, the xlim and ylim for a tight axis would be,
xlim([min(vector1), max(vector1)]);
ylim([min(vector2), max(vector2)]);
If you'd like to access those values from the line object handle 'h',
xlim([min(h.XData), max(h.XData)]);
ylim([min(h.YData), max(h.YData)]);
If you'd like to add 5% of the data range on each side so your max and min data points are not on the axis edges,
xlim([min(x),max(x)] + [-1,1]*.05*range(x))
ylim([min(y),max(y)] + [-1,1]*.05*range(y))
  4 comentarios
Adam Danz
Adam Danz el 21 de Ag. de 2019
Editada: Adam Danz el 22 de Ag. de 2019
Your proposal requires that an axis already exists. If you want to base "int" from my solution on the axis tick interval,
int = mean(diff(get(gca,'xtick')));
xl = [floor(min(x)/int)*int,ceil(max(x)/int)*int];
Chris
Chris el 23 de Ag. de 2019
yep good edit. initilization wont be a problem and the changed data points will be of the same magnitude so reusing tick should work.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by