time | Calls | line |
---|
| | 1 | function axReturn = newplot(hsave)
|
| | 2 | %NEWPLOT Prepares figure, axes for graphics according to NextPlot.
|
| | 3 | % H = NEWPLOT returns the handle of the prepared axes.
|
| | 4 | % H = NEWPLOT(HSAVE) prepares and returns an axes, but does not
|
| | 5 | % delete any objects whose handles appear in HSAVE. If HSAVE is
|
| | 6 | % specified, the figure and axes containing HSAVE are prepared
|
| | 7 | % instead of the current axes of the current figure. If HSAVE is
|
| | 8 | % empty, NEWPLOT behaves as if it were called without any inputs.
|
| | 9 | %
|
| | 10 | % NEWPLOT is a standard preamble command that is put at
|
| | 11 | % the beginning of graphics functions that draw graphs
|
| | 12 | % using only low-level object creation commands. NEWPLOT
|
| | 13 | % "does the right thing" in terms of determining which axes and/or
|
| | 14 | % figure to draw the plot in, based upon the setting of the
|
| | 15 | % NextPlot property of axes and figure objects, and returns a
|
| | 16 | % handle to the appropriate axes.
|
| | 17 | %
|
| | 18 | % The "right thing" is:
|
| | 19 | %
|
| | 20 | % First, prepare a figure for graphics:
|
| | 21 | % Clear and reset the current figure using CLF RESET if its NextPlot
|
| | 22 | % is 'replace', or clear the current figure using CLF if its
|
| | 23 | % NextPlot is 'replacechildren', or reuse the current figure as-is
|
| | 24 | % if its NextPlot is 'add', or if no figures exist, create a figure.
|
| | 25 | % When the figure is prepared, set its NextPlot to 'add', and then
|
| | 26 | % prepare an axes in that figure:
|
| | 27 | % Clear and reset the current axes using CLA RESET if its NextPlot
|
| | 28 | % is 'replace', or clear the current axes using CLA if its NextPlot
|
| | 29 | % is 'replacechildren', or reuse the current axes as-is if its
|
| | 30 | % NextPlot is 'add', or if no axes exist, create an axes.
|
| | 31 | %
|
| | 32 | % See also HOLD, ISHOLD, FIGURE, AXES, CLA, CLF.
|
| | 33 |
|
| | 34 | % Copyright 1984-2017 The MathWorks, Inc.
|
| | 35 | % Built-in function.
|
| | 36 |
|
< 0.001 | 2 | 37 | if nargin == 0 || isempty(hsave)
|
< 0.001 | 2 | 38 | hsave = [];
|
| | 39 | elseif ~isscalar(hsave) || ~ishghandle(hsave)
|
| | 40 | error(message('MATLAB:newplot:InvalidHandle'))
|
| | 41 | else
|
| | 42 | % Make sure we have an object handle.
|
| | 43 | hsave = handle(hsave);
|
| | 44 | end
|
| | 45 |
|
| | 46 |
|
0.005 | 2 | 47 | fig = gobjects(0);
|
< 0.001 | 2 | 48 | ax = gobjects(0);
|
| | 49 |
|
< 0.001 | 2 | 50 | if ~isempty(hsave)
|
| | 51 | obj = hsave;
|
| | 52 | while ~isempty(obj)
|
| | 53 | if isgraphics(obj, 'figure')
|
| | 54 | fig = obj;
|
| | 55 | elseif isgraphics(obj, 'axes') || isgraphics(obj,'polaraxes')
|
| | 56 | ax = obj;
|
| | 57 | end
|
| | 58 | obj = obj.Parent;
|
| | 59 | end
|
| | 60 | end
|
| | 61 |
|
< 0.001 | 2 | 62 | if isempty(fig)
|
< 0.001 | 2 | 63 | fig = gcf;
|
< 0.001 | 2 | 64 | end
|
| | 65 |
|
0.001 | 2 | 66 | fig = ObserveFigureNextPlot(fig, hsave);
|
| | 67 |
|
| | 68 | % Set figure's NextPlot property to 'add' after obeying the previous setting.
|
< 0.001 | 2 | 69 | fig.NextPlot = 'add';
|
| | 70 |
|
< 0.001 | 2 | 71 | checkNextPlot = true;
|
< 0.001 | 2 | 72 | if isempty(ax)
|
0.018 | 2 | 73 | ax = gca(fig);
|
< 0.001 | 2 | 74 | if ~isa(ax,'matlab.graphics.axis.Axes')
|
| | 75 | if isprop(ax,'NextPlot') && ishold(ax)
|
| | 76 | error(message('MATLAB:newplot:HoldOnMixing'))
|
| | 77 | else
|
| | 78 | ax = matlab.graphics.internal.swapaxes(ax,@axes);
|
| | 79 |
|
| | 80 | % We just creaetd a new axes, no need to check NextPlot
|
| | 81 | checkNextPlot = false;
|
| | 82 | end
|
| | 83 | end
|
| | 84 | elseif ~any(ishghandle(ax))
|
| | 85 | error(message('MATLAB:newplot:NoAxesParent'))
|
| | 86 | end
|
| | 87 |
|
< 0.001 | 2 | 88 | if checkNextPlot
|
0.014 | 2 | 89 | ax = ObserveAxesNextPlot(ax, hsave);
|
< 0.001 | 2 | 90 | end
|
| | 91 |
|
< 0.001 | 2 | 92 | if nargout
|
< 0.001 | 2 | 93 | axReturn = ax;
|
< 0.001 | 2 | 94 | end
|
Other subfunctions in this file are not included in this listing.