How do I move the x-axis so that it always intercepts the y-axis at y=0 on a two-dimensional plot?

16 visualizzazioni (ultimi 30 giorni)
I would like to have the x-axis intercept the y-axis at y=0, but the range of the y-axis must include positive and negative values. I would like to know whether there is a way to force the x-axis to cross the y-axis at y = 0;

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 27 Giu 2009
In MATLAB there is no way to change the position of the x-axis on an axes object.
To work around this issue, try applying the attached function drawaxis.m. This function will copy the values and tick marks of a specified axis and force it to cross the opposing axis at the desired location.
This function is limited. Only apply it after the axes text is formatted correctly, and the axes limits are set appropriately. Only issue the function once per axis. Since some of the axes properties must be removed, the axis may not be redrawn properly upon issuing the function successive times.
To use this function:
1. Download the file drawaxis.m to a directory on the MATLAB path.
2. Create a sinusoid plot by entering the following at the MATLAB Command Prompt:
t = -pi:pi/100:pi;
plot(t, sin(10*t))
xlabel(x axis)
3. Move the x-axis so it crosses at y=0 by entering the following at the MATLAB Command Prompt :
drawaxis(gca, 'x', 0, 'movelabel', 1)
There is some documentation associated with this function, which you can view by entering
help drawaxis
at the MATLAB Command Prompt.

Più risposte (0)

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by