Borrar filtros
Borrar filtros

shift a plot in the vertical direction?

30 visualizaciones (últimos 30 días)
Shani
Shani el 21 de Nov. de 2013
Comentada: Henry Ebili el 12 de Abr. de 2016
How can I shift a plot in the vertical direction?
  1 comentario
Image Analyst
Image Analyst el 23 de Nov. de 2013
Here is what Shani asked, so that it will still be here when she deletes this question:
How can I shift a plot in the vertical direction?

Iniciar sesión para comentar.

Respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 21 de Nov. de 2013
Editada: Azzi Abdelmalek el 21 de Nov. de 2013
k=2
plot(y+k)
%or
plot(x,y+k)
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 21 de Nov. de 2013
Editada: Azzi Abdelmalek el 21 de Nov. de 2013
This is the code, just try it
Henry Ebili
Henry Ebili el 12 de Abr. de 2016
What then, is "y" in your argument?

Iniciar sesión para comentar.


HJ
HJ el 21 de Nov. de 2013
It's not the most elegant solution, but you could use handles to simply slide all the coordinates in one direction. For example:
% Plot twenty random points
plot(100*rand(1,20),'o');
axis([0 20 0 100]);
% Get coordinates of all objects in plot (note that you
% won't need to do this if you keep track of the handle
% of each point as you plot it...
plotObjects = get(gca, 'Children');
% Shift all points in the Y directon
offset = 5;
set(plotObjects, 'YData', get(plotObjects, 'YData') + offset);
If you run that last set command multiple times, you should see your points gradually shifting up and out of view.
  1 comentario
HJ
HJ el 22 de Nov. de 2013
More than half of what I posted is comments. The code part is really quite short.
In any case, the "right" approach (if there is such a thing) depends on what you're trying to do. If you just want to plot an existing bunch of numbers with an offset, then yes, Azzi's approach will work just fine. If you want to shift things on an existing plot, then the handle graphics stuff is a good way to do it.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming 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!

Translated by