Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
add line w/o changing limits

Subject: add line w/o changing limits

From: Assaf Weinstein

Date: 7 Jul, 2010 09:46:03

Message: 1 of 5

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

Subject: add line w/o changing limits

From: vedenev

Date: 7 Jul, 2010 10:10:41

Message: 2 of 5

set(gca, 'xlim',xlim(gca), 'ylim',ylim(gca)) do nothing because you
set same limits.

try:
axis manual

From matlab doc:
axis manual and axis(axis) freezes the scaling at the current limits,
so that if hold is on, subsequent plots use the same limits. This sets
the XLimMode, YLimMode, and ZLimMode properties to manual.

-----------------------------------------
Maxim Vedenev, MATLAB Custom Programming
vedenev@ngs.ru
http://simulations.narod.ru/

Subject: add line w/o changing limits

From: Walter Roberson

Date: 7 Jul, 2010 18:26:47

Message: 3 of 5

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')

Subject: add line w/o changing limits

From: Jan Simon

Date: 7 Jul, 2010 22:40:21

Message: 4 of 5

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

Subject: add line w/o changing limits

From: Yair Altman

Date: 8 Jul, 2010 06:30:11

Message: 5 of 5

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i12vol$lph$1@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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us