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-2018 The MathWorks, Inc.
|
| | 35 | % Built-in function.
|
| | 36 |
|
0.001 | 60 | 37 | if nargin == 0 || isempty(hsave)
|
< 0.001 | 60 | 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);
|
< 0.001 | 60 | 44 | end
|
| | 45 |
|
| | 46 | % Get the ancestor axes and figure from the input (if present).
|
0.010 | 60 | 47 | fig = gobjects(0);
|
0.004 | 60 | 48 | ax = gobjects(0);
|
< 0.001 | 60 | 49 | if ~isempty(hsave)
|
| | 50 | obj = hsave;
|
| | 51 | while ~isempty(obj)
|
| | 52 | if isgraphics(obj, 'figure')
|
| | 53 | fig = obj;
|
| | 54 | elseif isgraphics(obj,'axes') || isgraphics(obj,'polaraxes') || isgraphics(obj,'geoaxes')
|
| | 55 | ax = obj;
|
| | 56 | end
|
| | 57 | obj = obj.Parent;
|
| | 58 | end
|
< 0.001 | 60 | 59 | end
|
| | 60 |
|
| | 61 | % If no axes or figure was found, create a new figure. Check if the axes is
|
| | 62 | % empty to avoid creating a figure if an unparented axes was provided.
|
< 0.001 | 60 | 63 | if isempty(fig) && isempty(ax)
|
0.001 | 60 | 64 | fig = gcf;
|
< 0.001 | 60 | 65 | end
|
| | 66 |
|
< 0.001 | 60 | 67 | if ~isempty(fig)
|
| | 68 | % Prepare the figure based on the NextPlot property.
|
0.004 | 60 | 69 | fig = ObserveFigureNextPlot(fig, hsave);
|
| | 70 |
|
| | 71 | % Set figure's NextPlot property to 'add' after obeying the previous setting.
|
0.002 | 60 | 72 | fig.NextPlot = 'add';
|
< 0.001 | 60 | 73 | end
|
| | 74 |
|
< 0.001 | 60 | 75 | checkNextPlot=true;
|
< 0.001 | 60 | 76 | if isempty(ax)
|
0.195 | 60 | 77 | ax = gca(fig);
|
< 0.001 | 60 | 78 | if ~isa(ax,'matlab.graphics.axis.Axes') &&...
|
| | 79 | ~isa(ax,'matlab.ui.control.UIAxes')
|
| | 80 | if isprop(ax,'NextPlot') && ishold(ax)
|
| | 81 | error(message('MATLAB:newplot:HoldOnMixing',ax.Type))
|
| | 82 | else
|
| | 83 | ax = matlab.graphics.internal.swapaxes(ax,@axes);
|
| | 84 |
|
| | 85 | % We just created a new axes, no need to check NextPlot
|
| | 86 | checkNextPlot = false;
|
| | 87 | end
|
< 0.001 | 60 | 88 | end
|
| | 89 | elseif ~any(ishghandle(ax))
|
| | 90 | error(message('MATLAB:newplot:NoAxesParent'))
|
< 0.001 | 60 | 91 | end
|
| | 92 |
|
< 0.001 | 60 | 93 | if checkNextPlot
|
0.063 | 60 | 94 | ax = ObserveAxesNextPlot(ax, hsave);
|
< 0.001 | 60 | 95 | end
|
| | 96 |
|
< 0.001 | 60 | 97 | if nargout
|
< 0.001 | 60 | 98 | axReturn = ax;
|
< 0.001 | 60 | 99 | end
|
Other subfunctions in this file are not included in this listing.