Why do the x-axis tick marks overlap when using the PLOTYY function in MATLAB?

1 visualización (últimos 30 días)
When I execute the commands:
for i=1:0.1:10
P = i*0.9;
Pnew= 1.05*exp(-(3.24*(i*(1.8+i*0.027)-P)/279))*((i-(0.5*exp(3.24*(i*(1.8+i*0.027)-P)/74))));
P=Pnew;
eff=Pnew/(i*1.8);
[ax, h1, h2] = plotyy(i,Pnew,i,eff,'plot');
set(get(ax(1),'Ylabel'),'String','Power')
set(get(ax(2),'Ylabel'),'String','Effeciency')
hold on
end
xlabel('Current[A]')
title('Diode LIV Plot')
I receive a plot with overlapping tick marks along the x-axis.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 26 de Jul. de 2010
The PLOTYY function in MATLAB behaves this way because of how it handles redrawing on its two axes. The first axes created by PLOTYY is repeatedly used to draw the next plot by setting its "NextPlot" property to "add". However, a new second axes is created every time PLOTYY is called to redraw a plot on the axes.
In this example, the PLOTYY function is repeatedly called from within a FOR loop with different data values. Since these data values have different ranges, the newly-created second axes will have different "Xlim" values. These limits do not match with those of the previously created second axes, hence the x-axis tick marks do not coincide.
To work around this issue, you can explicitly specify the "Xlim" and "Ylim" properties for both axes as shown in the following code:
for i=1:0.1:10
P = i*0.9;
Pnew= 1.05*exp(-(3.24*(i*(1.8+i*0.027)-P)/279))*((i-(0.5*exp(3.24*(i*(1.8+i*0.027)-P)/74))));
P=Pnew;
eff=Pnew/(i*1.8);
[ax, h1, h2] = plotyy(i,Pnew,i,eff,'plot');
set(get(ax(1),'Ylabel'),'String','Power')
set(get(ax(2),'Ylabel'),'String','Efficiency')
axis(ax(1),[1 10 1 10]);
axis(ax(2),[1 10 -1 1.5]);
hold on
end
xlabel('Current[A]')
title('Diode LIV Plot')
This will ensure that the x-axis tick marks remain aligned.

Más respuestas (0)

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Productos


Versión

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by