How to create axes without any connection to the current plot?

I would like to create/define axes to use it later, and do something like this:
ax = axes('Position',[0,0,0.1,0.1],'Visible','off','XLim',[0 10],'YLim',[0 5]);
However this command affect the current plots in a for cycle. Why? And how to create axes without modifying the current plot(s)?

Antworten (1)

Jan
Jan am 1 Okt. 2015
If you use plot without specifying an axes object to plot in, Matlab draws to the "current axes", see help gca. The "current axes" is the last axes object, which has been accessed. Of course Matlab does this, because it cannot guess where you want the lines to appear.
Either you make the wanted axes the "current axes" using the axes comamnd with the handle of the wanted object:
axes(AxesHandle)
But this still fails, if a nervous user clicks on any axes during the code runs. So the only stable solution is to determine the axes to plot in:
plot(1:10, rand(1, 10), 'Parent', AxesHandle);
For this you have to store a list of available axes. This means some effort during the programming, but better spend some additional seconds during typing than hours during debugging and calming users.

Kategorien

Mehr zu Graphics Object Programming finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 1 Okt. 2015

Beantwortet:

Jan
am 1 Okt. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by