From: Ed Nieters on
Hi

I want a figure window with x and y axes for a line plot. The X-axis limits should stay unchanged but be able to plot lines within the limits. I do not want prior plots to stay on the screen ("hold on" is not correct).

I run this code:
figure(1)
set(gca, 'XlimMode', 'manual')
xlim([-5,5])
get(gca, 'XlimMode') % says 'manual' as expected
get(gca, 'Xlim') % says -5 5 as expected

so far so good
x=-pi:.1:pi
y=sin(pi)
plot(x,y)

the x-axis limits change from -4 to 4 and get(gca, 'XlimMode') says auto and
get(gca, 'Xlim') says -4 to 4.

How can I maintain the desired -5 5 limits?

Again, I don't want hold on behavior because if I later to
x2=x+1
plot(x2,y)

I want the x,y plot to be erased and x2,y displayed but x axis still run -5 5.
If I have to do the xlim() call after each plot, the figure flickers too much.

Thanks.

--Ed
From: Walter Roberson on
Ed Nieters wrote:

> I want a figure window with x and y axes for a line plot. The X-axis
> limits should stay unchanged but be able to plot lines within the
> limits. I do not want prior plots to stay on the screen ("hold on" is
> not correct).
>
> I run this code:
> figure(1)
> set(gca, 'XlimMode', 'manual')
> xlim([-5,5])
> get(gca, 'XlimMode') % says 'manual' as expected
> get(gca, 'Xlim') % says -5 5 as expected
>
> so far so good
> x=-pi:.1:pi
> y=sin(pi)
> plot(x,y)
>
> the x-axis limits change from -4 to 4 and get(gca, 'XlimMode') says auto
> and get(gca, 'Xlim') says -4 to 4.
>
> How can I maintain the desired -5 5 limits?
>
> Again, I don't want hold on behavior because if I later to x2=x+1
> plot(x2,y)
>
> I want the x,y plot to be erased and x2,y displayed but x axis still run
> -5 5.
> If I have to do the xlim() call after each plot, the figure flickers too
> much.

If you examine the "hold" documentation, you will find that if the axes
NextPlot property is 'replace' then the effect is the same as cla reset
(clear axes resetting all properties), which is going to reset the XLim
property. I suggest you set the axes NextPlot property to 'replacechildren'.

I also recommend that over the longer term, you learn about setting the
Visible property to off before making changes and then back to on when
you are finished, so that the plot does not flicker. I further recommend
that you study using handle graphics handles and changing the XData and
YData properties of the lineseries that plot() returns rather than
constructing an entire new plot.