From: Assaf Weinstein on
Hi,

How do I add a line to an existing figure, without changing xlim, ylim?

What I would use is

set(gca, 'xlim',xlim(gca), 'ylim',ylim(gca))

before adding the line..

Is there any better way to do this?

Thanks,

Assaf
From: Walter Roberson on
vedenev wrote:
> set(gca, 'xlim',xlim(gca), 'ylim',ylim(gca)) do nothing because you
> set same limits.

You are mistaken. The original poster's code would have worked.

>> figure(123);t = plot(exp(1:5)); ax = get(t,'Parent');
disp(get(ax,'XLimMode'));set(ax,'XLim',[0 2]);disp(get(ax,'XLimMode'));

auto
manual


http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#XLimMode
XLimMode, YLimMode, ZLimMode

{auto} | manual

MATLAB or user-controlled limits. The axis limits mode determines whether
MATLAB calculates axis limits based on the data plotted (for example, the
XData, YData, or ZData of the axes children) or uses the values explicitly set
with the XLim, YLim, or ZLim property, in which case, the respective limits
mode is set to manual.



The direct mechanism for the original poster would be to

set(gca,'XLimMode','manual','YLimMode','manual')
From: Jan Simon on
Dear Assaf,

> How do I add a line to an existing figure, without changing xlim, ylim?
> What I would use is
> set(gca, 'xlim',xlim(gca), 'ylim',ylim(gca))
> before adding the line..
> Is there any better way to do this?

set(gca, 'XLimMode', 'manual')

There is an undocumented feature since Matlab 6.5:
plot(1:10, 1:10);
line(1:11, 2:2:22, 'YLimInclude', 'off', 'XLimInclude', 'off');
Then the 2nd line is not used to determine the limits.
Although this property has a high practical use and is existing for many years, it could be removed in a future release.

Good luck, Jan
From: Yair Altman on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i12vol$lph$1(a)fred.mathworks.com>...
> Dear Assaf,
>
> > How do I add a line to an existing figure, without changing xlim, ylim?
> > What I would use is
> > set(gca, 'xlim',xlim(gca), 'ylim',ylim(gca))
> > before adding the line..
> > Is there any better way to do this?
>
> set(gca, 'XLimMode', 'manual')
>
> There is an undocumented feature since Matlab 6.5:
> plot(1:10, 1:10);
> line(1:11, 2:2:22, 'YLimInclude', 'off', 'XLimInclude', 'off');
> Then the 2nd line is not used to determine the limits.
> Although this property has a high practical use and is existing for many years, it could be removed in a future release.
>
> Good luck, Jan

http://UndocumentedMatlab.com/blog/plot-liminclude-properties/

Yair Altman
http://UndocumentedMatlab.com
 | 
Pages: 1
Prev: filter design
Next: transparent uicontrols