Borrar filtros
Borrar filtros

Drawing X and Y axis on 2D plot

234 visualizaciones (últimos 30 días)
David Polcari
David Polcari el 12 de Jun. de 2012
Comentada: Sidharth A Narayanan el 22 de Mzo. de 2023
Hi everyone,
I have been searching for an easy way to draw the x and y axis on a plot but cannot seem to do it. For example, if I have a plot that has range [-2 10] for x and [-200 400] for y, I would like to be able to draw a line along x = 0 and y = 0. I have looked at certain functions such as axescenter but this draws the axes in the exact center so it does not work for me. The style is great but I can't get it along the axes. Anyone have any ideas?

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Jun. de 2012
xL = xlim;
yL = ylim;
line([0 0], yL); %x-axis
line(xL, [0 0]); %y-axis
  10 comentarios
Zhao Lu
Zhao Lu el 10 de Ag. de 2022
Thanks so much
Sidharth A Narayanan
Sidharth A Narayanan el 22 de Mzo. de 2023
I think you interchanged the x-axis and y-axis ...

Iniciar sesión para comentar.

Más respuestas (3)

Brian Russell
Brian Russell el 30 de Abr. de 2021
Why does everyone give such complicated answers to this question? The answer is xline(0) and yline(0).
  4 comentarios
Brian Russell
Brian Russell el 21 de Jun. de 2021
Thanks, Sajib, but I don't know how to move it to the top. I think an administrator has to do that. I think that in an earlier version of MATLAB, the answer at the top was the correct one, but the answer I gave must be a new feature.
Alex Henderson
Alex Henderson el 23 de Feb. de 2023
"Why does everyone give such complicated answers to this question?"
Probably because these functions only appeared in R2018b. Still, useful to know they're there now.

Iniciar sesión para comentar.


Steven Lord
Steven Lord el 1 de Sept. de 2016
As of release R2015b you can set the axes XAxisLocation and YAxisLocation properties to 'origin' to get the axes lines to cross at the origin.

Kajeen Hassan
Kajeen Hassan el 28 de En. de 2020
A parametric equation to plot the function x= 1.5 sin(5t), y= 1.5 cos(3t) , plot the function for 0<=t<=2* pi. Format the plot such that the both axes will range from -2 to 2.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by