Mercurial > hg > octave-nkf
annotate scripts/plot/util/subplot.m @ 19898:4197fc428c7d
maint: Update copyright notices for 2015.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Feb 2015 14:19:08 -0500 |
parents | 8064b5cdbc11 |
children | 9fc020886ae9 |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19888
diff
changeset
|
1 ## Copyright (C) 1995-2015 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
1540 | 18 |
3368 | 19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} subplot (@var{rows}, @var{cols}, @var{index}) |
3368 | 21 ## @deftypefnx {Function File} {} subplot (@var{rcn}) |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
22 ## @deftypefnx {Function File} {} subplot (@var{hax}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
23 ## @deftypefnx {Function File} {} subplot (@dots{}, "align") |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
24 ## @deftypefnx {Function File} {} subplot (@dots{}, "replace") |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
25 ## @deftypefnx {Function File} {} subplot (@dots{}, "position", @var{pos}) |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
26 ## @deftypefnx {Function File} {} subplot (@dots{}, @var{prop}, @var{val}, @dots{}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
27 ## @deftypefnx {Function File} {@var{hax} =} subplot (@dots{}) |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
28 ## Set up a plot grid with @var{rows} by @var{cols} subwindows and set the |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
29 ## current axes for plotting (@code{gca}) to the location given by @var{index}. |
3426 | 30 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
31 ## If only one numeric argument is supplied, then it must be a three digit |
17513
fedcd3717ebc
doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17428
diff
changeset
|
32 ## value specifying the number of rows in digit 1, the number of |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
33 ## columns in digit 2, and the plot index in digit 3. |
17085
d3ebc3f9bdbf
doc update for grid and subplot
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
17022
diff
changeset
|
34 ## |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
35 ## The plot index runs row-wise; First, all columns in a row are numbered |
3368 | 36 ## and then the next row is filled. |
3426 | 37 ## |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
38 ## For example, a plot with 2x3 grid will have plot indices running as follows: |
3368 | 39 ## @tex |
40 ## \vskip 10pt | |
41 ## \hfil\vbox{\offinterlineskip\hrule | |
42 ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr | |
7107 | 43 ## height13pt&1&2&3\cr height12pt&&&\cr\noalign{\hrule} |
44 ## height13pt&4&5&6\cr height12pt&&&\cr\noalign{\hrule}}} | |
3368 | 45 ## \hfil |
46 ## \vskip 10pt | |
47 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8350
diff
changeset
|
48 ## @ifnottex |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
49 ## |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
50 ## @example |
3368 | 51 ## @group |
7040 | 52 ## +-----+-----+-----+ |
53 ## | 1 | 2 | 3 | | |
54 ## +-----+-----+-----+ | |
55 ## | 4 | 5 | 6 | | |
56 ## +-----+-----+-----+ | |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
57 ## @end group |
6257 | 58 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
59 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
60 ## @end ifnottex |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
61 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
62 ## @var{index} may also be a vector. In this case, the new axis will enclose |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
63 ## the grid locations specified. The first demo illustrates this: |
12476
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
64 ## |
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
65 ## @example |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
66 ## demo ("subplot", 1) |
12476
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
67 ## @end example |
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
68 ## |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
69 ## The index of the subplot to make active may also be specified by its axes |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
70 ## handle, @var{hax}, returned from a previous @code{subplot} command. |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
71 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
72 ## If the option @qcode{"align"} is given then the plot boxes of the subwindows |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
73 ## will align, but this may leave no room for axis tick marks or labels. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
74 ## |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
75 ## If the option @qcode{"replace"} is given then the subplot axis will be |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
76 ## reset, rather than just switching the current axis for plotting to the |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
77 ## requested subplot. |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
78 ## |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
79 ## The @qcode{"position"} property can be used to exactly position the subplot |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
80 ## axes within the current figure. The option @var{pos} is a 4-element vector |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
81 ## [x, y, width, height] that determines the location and size of the axes. |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
82 ## The values in @var{pos} are normalized in the range [0,1]. |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
83 ## |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
84 ## Any property/value pairs are passed directly to the underlying axes object. |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
85 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17095
diff
changeset
|
86 ## If the output @var{hax} is requested, subplot returns the axis handle for |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
87 ## the subplot. This is useful for modifying the properties of a subplot |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
88 ## using @code{set}. |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
89 ## @seealso{axes, plot, gca, set} |
3368 | 90 ## @end deftypefn |
1540 | 91 |
2312 | 92 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
93 ## Adapted-By: jwe | |
1540 | 94 |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
95 function h = subplot (varargin) |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
96 |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
97 align_axes = false; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
98 replace_axes = false; |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
99 have_position = false; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
100 initial_args_decoded = false; |
6163 | 101 |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
102 if (nargin >= 3) |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
103 ## R, C, N? |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
104 arg1 = varargin{1}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
105 arg2 = varargin{2}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
106 arg3 = varargin{3}; |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
107 if ( isnumeric (arg1) && isscalar (arg1) |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
108 && isnumeric (arg2) && isscalar (arg2) |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
109 && isnumeric (arg3)) |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
110 rows = arg1; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
111 cols = arg2; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
112 index = arg3; |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
113 varargin(1:3) = []; |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
114 initial_args_decoded = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
115 endif |
1540 | 116 endif |
117 | |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
118 if (! initial_args_decoded && nargin > 1) |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
119 ## check for "position", pos, ... |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
120 if (strcmpi (varargin{1}, "position")) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
121 arg = varargin{2}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
122 if (isnumeric (arg) && numel (arg) == 4) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
123 pos = arg; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
124 varargin(1:2) = []; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
125 have_position = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
126 initial_args_decoded = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
127 else |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
128 error ("subplot: POSITION must be a 4-element numeric array"); |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
129 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
130 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
131 endif |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17860
diff
changeset
|
132 |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
133 if (! initial_args_decoded && nargin > 0) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
134 arg = varargin{1}; |
17303
8520c264619c
subplot.m: Use isaxes() function instead of ishandle() to check for axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
135 if (nargin == 1 && isaxes (arg)) |
8520c264619c
subplot.m: Use isaxes() function instead of ishandle() to check for axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
136 ## Axes handle |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
137 axes (arg); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
138 cf = get (0, "currentfigure"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
139 set (cf, "nextplot", "add"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
140 return; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
141 elseif (isscalar (arg) && arg >= 0) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
142 ## RCN? |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
143 index = rem (arg, 10); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
144 arg = (arg - index) / 10; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
145 cols = rem (arg, 10); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
146 arg = (arg - cols) / 10; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
147 rows = rem (arg, 10); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
148 varargin(1) = []; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
149 initial_args_decoded = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
150 else |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
151 error ("subplot: expecting axes handle or RCN argument"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
152 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
153 endif |
1540 | 154 |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
155 if (! initial_args_decoded) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
156 print_usage (); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
157 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
158 |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
159 if (! have_position) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
160 cols = round (cols); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
161 rows = round (rows); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
162 index = round (index); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
163 |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
164 if (any (index < 1) || any (index > rows*cols)) |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
165 error ("subplot: INDEX value must be >= 1 and <= ROWS*COLS"); |
1540 | 166 endif |
167 | |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
168 if (rows < 1 || cols < 1 || index < 1) |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
169 error ("subplot: ROWS, COLS, and INDEX must be be positive"); |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
170 endif |
1540 | 171 endif |
172 | |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
173 ## Process "align" and "replace" options |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
174 idx = strcmpi (varargin, "align"); |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
175 if (any (idx)) |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
176 align_axes = true; |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
177 varargin(idx) = []; |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
178 endif |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
179 |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
180 idx = strcmpi (varargin, "replace"); |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
181 if (any (idx)) |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
182 replace_axes = true; |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
183 varargin(idx) = []; |
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
184 endif |
1540 | 185 |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
186 axesunits = get (0, "defaultaxesunits"); |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
187 cf = gcf (); |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
188 figureunits = get (cf, "units"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
189 unwind_protect |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
190 set (0, "defaultaxesunits", "normalized"); |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
191 set (cf, "units", "pixels"); |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
192 |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
193 ## FIXME: At the moment we force gnuplot to use the aligned mode |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
194 ## which will set "activepositionproperty" to "position". |
17860
93edd282a2bc
subplot.m: Matlab compatibility when "position" given (bug #40480).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
195 ## This can yield to text overlap between labels and titles. |
93edd282a2bc
subplot.m: Matlab compatibility when "position" given (bug #40480).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
196 ## See bug #31610. |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
197 if (strcmp (get (cf, "__graphics_toolkit__"), "gnuplot")) |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
198 align_axes = true; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
199 endif |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
200 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
201 if (! have_position) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
202 ## Subplots that cover more that one base subplot are not updated |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
203 align_axes = (align_axes || (! isscalar (index))); |
17860
93edd282a2bc
subplot.m: Matlab compatibility when "position" given (bug #40480).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
204 ## Normal case where subplot indices have been given |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
205 [pos, opos, li] = subplot_position (cf, rows, cols, index); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
206 else |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
207 ## Position is specified by the user. |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
208 li = zeros (1,4); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
209 align_axes = true; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
210 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
211 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
212 set (cf, "nextplot", "add"); |
17860
93edd282a2bc
subplot.m: Matlab compatibility when "position" given (bug #40480).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
213 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
214 found = false; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
215 kids = get (cf, "children"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
216 for child = kids(:)' |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
217 ## Check whether this child is still valid; this might not be the |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
218 ## case anymore due to the deletion of previous children (due to |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
219 ## "deletefcn" callback or for legends/colorbars that are deleted |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
220 ## with their corresponding axes). |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
221 if (! ishandle (child)) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
222 continue; |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
223 endif |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
224 if (strcmp (get (child, "type"), "axes")) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
225 ## Skip legend and colorbar objects. |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
226 if (any (strcmp (get (child, "tag"), {"legend", "colorbar"}))) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
227 continue; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
228 endif |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
229 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
230 if (isappdata (child, "__subplotposition__")) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
231 objpos = getappdata (child, "__subplotposition__"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
232 else |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
233 objpos = get (child, "position"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
234 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
235 if (all (abs (objpos - pos) < eps) && ! replace_axes) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
236 ## If the new axes are in exactly the same position |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
237 ## as an existing axes object, or if they share the same |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
238 ## appdata "__subplotposition__", use the existing axes. |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
239 found = true; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
240 hsubplot = child; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
241 else |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
242 ## If the new axes overlap an old axes object, delete the old axes. |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
243 objpos = get (child, "position"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
244 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
245 x0 = pos(1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
246 x1 = x0 + pos(3); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
247 y0 = pos(2); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
248 y1 = y0 + pos(4); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
249 objx0 = objpos(1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
250 objx1 = objx0 + objpos(3); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
251 objy0 = objpos(2); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
252 objy1 = objy0 + objpos(4); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
253 if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0)) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
254 delete (child); |
10549 | 255 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
256 endif |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
257 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
258 endfor |
1540 | 259 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
260 if (found) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
261 ## Switch to existing subplot and set requested properties |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
262 set (cf, "currentaxes", hsubplot); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
263 if (! isempty (varargin)) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
264 set (hsubplot, varargin{:}); |
17860
93edd282a2bc
subplot.m: Matlab compatibility when "position" given (bug #40480).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
265 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
266 else |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
267 hsubplot = axes ("box", "off", |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
268 "activepositionproperty", "position", |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
269 "position", pos, "looseinset", li, |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
270 varargin{:}); |
17860
93edd282a2bc
subplot.m: Matlab compatibility when "position" given (bug #40480).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
271 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
272 if (! align_axes) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
273 ## base position (no ticks, no annotation, no cumbersome neighbor) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
274 setappdata (hsubplot, "__subplotposition__", pos); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
275 ## max outerposition |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
276 setappdata (hsubplot, "__subplotouterposition__", opos); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
277 addlistener (hsubplot, "outerposition", @subplot_align); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
278 addlistener (hsubplot, "xaxislocation", @subplot_align); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
279 addlistener (hsubplot, "yaxislocation", @subplot_align); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
280 addlistener (hsubplot, "position", {@subplot_align, true}); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
281 subplot_align (hsubplot); |
17860
93edd282a2bc
subplot.m: Matlab compatibility when "position" given (bug #40480).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
282 endif |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
283 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
284 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
285 unwind_protect_cleanup |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
286 set (0, "defaultaxesunits", axesunits); |
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
287 set (cf, "units", figureunits); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
288 end_unwind_protect |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
289 |
6257 | 290 if (nargout > 0) |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
291 h = hsubplot; |
1540 | 292 endif |
293 | |
294 endfunction | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
295 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
296 function [pos, opos, li] = subplot_position (hf, nrows, ncols, idx) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
297 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
298 if (nrows == 1 && ncols == 1) |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
299 ## Trivial result for subplot (1,1,1) |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
300 pos = get (0, "defaultaxesposition"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
301 opos = get (0, "defaultaxesouterposition"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
302 li = get (0, "defaultaxeslooseinset"); |
17312
088d014a7fe2
Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents:
17303
diff
changeset
|
303 return; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
304 endif |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
305 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
306 ## Row/Column inside the axes array |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
307 row = ceil (idx / ncols); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
308 col = idx .- (row - 1) * ncols; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
309 row = [min(row) max(row)]; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
310 col = [min(col) max(col)]; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
311 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
312 ## Minimal margins around subplots defined in points |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
313 fig_units = get (hf, "units"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
314 set (hf, "units", "points"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
315 pts_size = get (gcf, "position")(3:4); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
316 xbasemargin = 6 / pts_size(1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
317 ybasemargin = 6 / pts_size(2); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
318 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
319 ## Column/row separation |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
320 margin.column = .2 / ncols + 2 * xbasemargin; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
321 margin.row = .2 / nrows + 2 * ybasemargin; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
322 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
323 set (hf, "units", fig_units); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
324 margin.left = xbasemargin; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
325 margin.right = xbasemargin; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
326 margin.bottom = ybasemargin; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
327 margin.top = ybasemargin; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
328 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
329 ## Boundary axes have default margins |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
330 borders = get (0, "defaultaxesposition"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
331 if (col(1) == 1) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
332 margin.left = borders(1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
333 else |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
334 margin.left = margin.column - margin.right; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
335 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
336 if (col(2) == ncols) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
337 margin.right = 1 - borders(1) - borders(3); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
338 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
339 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
340 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
341 if (row(2) == nrows) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
342 margin.bottom = borders(2); |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
343 else |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
344 margin.bottom = margin.row - margin.top; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
345 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
346 if (row(1) == 1) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
347 margin.top = 1 - borders(2) - borders(4); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
348 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
349 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
350 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
351 ## Compute base width and height |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
352 width = (borders(3) - (ncols - 1) * margin.column) / ncols; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
353 height = (borders(4) - (nrows - 1) * margin.row) /nrows; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
354 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
355 ## Position, outerposition and looseinset |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
356 x0 = borders(1) + (col(1) - 1) * (width + margin.column); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
357 y0 = borders(2) + (nrows - row(2)) * (height + margin.row); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
358 width += diff (col) * (width + margin.column); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
359 height += diff (row) * (height + margin.row); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
360 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
361 pos = [x0 y0 width height]; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
362 opos = [(x0 - margin.left), (y0 - margin.bottom), ... |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
363 (width + margin.left + margin.right), ... |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
364 (height + margin.bottom + margin.top)]; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
365 li = [margin.left, margin.bottom, margin.right, margin.top]; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
366 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
367 endfunction |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
368 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
369 function subplot_align (h, d, rmupdate = false) |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
370 persistent updating = false; |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
371 if (! updating) |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
372 if (rmupdate) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
373 ## The "position" property has been changed from outside this |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
374 ## routine. Don't update anymore. |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
375 if (isappdata (h, "__subplotposition__")) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
376 rmappdata (h, "__subplotposition__"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
377 rmappdata (h, "__subplotouterposition__"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
378 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
379 return |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
380 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
381 |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
382 unwind_protect |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
383 updating = true; |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
384 hf = ancestor (h, "figure"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
385 children = get (hf, "children"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
386 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
387 ## Base position of the subplot |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
388 pos = getappdata (children, "__subplotposition__"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
389 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
390 if (iscell (pos)) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
391 do_align = ! cellfun (@isempty, pos); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
392 pos = cell2mat (pos(do_align)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
393 else |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
394 return |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
395 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
396 hsubplots = children(do_align); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
397 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
398 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
399 ## There may be mixed subplot series (e.g. 2-by-6 and 1-by-6) in |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
400 ## the same figure. Only subplots that have the same width and |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
401 ## height as this one are updated. |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
402 if (any (h == hsubplots)) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
403 width = pos(h == hsubplots, 3); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
404 height = pos(h == hsubplots, 4); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
405 do_align = (pos(:,3) == width) & (pos(:,4) == height); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
406 hsubplots(! do_align) = []; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
407 pos(! do_align,:) = []; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
408 else |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
409 return |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
410 endif |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
411 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
412 ## Reset outerpositions to their default value |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
413 opos = getappdata (hsubplots, "__subplotouterposition__"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
414 if (iscell (opos)) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
415 opos = cell2mat (opos); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
416 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
417 for ii = 1:numel (hsubplots); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
418 set (hsubplots(ii), "outerposition", opos(ii,:), ... |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
419 "activepositionproperty", "position"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
420 endfor |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
421 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
422 ## Compare current positions to default and compute the new ones |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
423 curpos = get (hsubplots, "position"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
424 if (iscell (curpos)) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
425 curpos = cell2mat (curpos); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
426 endif |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
427 dx0 = max (curpos(:,1) - pos(:,1)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
428 dx0(dx0<0) = 0; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
429 dx1 = max ((pos(:,1) + pos(:,3)) - (curpos(:,1) + curpos(:,3))); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
430 dx1(dx1<0) = 0; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
431 dy0 = max (curpos(:,2) - pos(:,2)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
432 dy0(dy0<0) = 0; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
433 dy1 = max ((pos(:,2) + pos(:,4)) - (curpos(:,2) + curpos(:,4))); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
434 dy1(dy1<0) = 0; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
435 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
436 pos(:,1) += dx0; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
437 pos(:,2) += dy0; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
438 pos(:,3) -= dx0 + dx1; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
439 pos(:,4) -= dy0 + dy1; |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
440 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
441 for ii = 1:numel (hsubplots) |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
442 set (hsubplots(ii), "position", pos(ii,:)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
443 endfor |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
444 |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
445 unwind_protect_cleanup |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
446 updating = false; |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
447 end_unwind_protect |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
448 endif |
17428
9304514b566c
subplot.m: Don't clear axes when switching to existing subplot (most of a fix for bug #39874).
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
449 |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
450 endfunction |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
451 |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17312
diff
changeset
|
452 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
453 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
454 %! clf; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
455 %! r = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
456 %! c = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
457 %! fmt = {'horizontalalignment', 'center', 'verticalalignment', 'middle'}; |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
458 %! for n = 1 : r*c |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
459 %! subplot (r, c, n); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
460 %! xlabel (sprintf ('xlabel #%d', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
461 %! ylabel (sprintf ('ylabel #%d', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
462 %! title (sprintf ('title #%d', n)); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
463 %! text (0.5, 0.5, sprintf ('subplot(%d,%d,%d)', r, c, n), fmt{:}); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
464 %! axis ([0 1 0 1]); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
465 %! end |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
466 %! subplot (r, c, 1:3); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
467 %! xlabel (sprintf ('xlabel #%d:%d', 1, 3)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
468 %! ylabel (sprintf ('ylabel #%d:%d', 1, 3)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
469 %! title (sprintf ('title #%d:%d', 1, 3)); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
470 %! text (0.5, 0.5, sprintf ('subplot(%d,%d,%d:%d)', r, c, 1, 3), fmt{:}); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
471 %! axis ([0 1 0 1]); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
472 |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
473 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
474 %! clf; |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
475 %! x = 0:1; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
476 %! for n = 1:4 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
477 %! subplot (2,2,n, 'align'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
478 %! plot (x, x); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
479 %! xlabel (sprintf ('xlabel (2,2,%d)', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
480 %! ylabel (sprintf ('ylabel (2,2,%d)', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
481 %! title (sprintf ('title (2,2,%d)', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
482 %! end |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
483 %! subplot (1,2,1, 'align'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
484 %! plot (x, x); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
485 %! xlabel ('xlabel (1,2,1)'); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
486 %! ylabel ('ylabel (1,2,1)'); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
487 %! title ('title (1,2,1)'); |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
488 |
16975 | 489 %!demo |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
490 %! clf; |
16975 | 491 %! x = 0:10; |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
492 %! ax(1) = subplot (221); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
493 %! set (ax(1), 'tag', '1'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
494 %! plot (x, rand (3, 11)) |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
495 %! title ('x & y labels & ticklabels'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
496 %! xlabel xlabel |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
497 %! ylabel ylabel |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
498 %! ax(2) = subplot (222); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
499 %! set (ax(2), 'tag', '2'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
500 %! plot (x, rand (3, 11)) |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
501 %! title ('no labels'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
502 %! axis ('nolabel','tic') |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
503 %! ax(3) = subplot (223); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
504 %! set (ax(3), 'tag', '3'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
505 %! plot (x, rand (3, 11)) |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
506 %! title ('no labels'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
507 %! axis ('nolabel','tic') |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
508 %! ax(4) = subplot (224); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
509 %! set (ax(4), 'tag', '4'); |
16975 | 510 %! plot (x, rand (3, 11)) |
511 %! title ('x & y labels & ticklabels'); | |
512 %! xlabel xlabel | |
513 %! ylabel ylabel | |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
514 |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
515 %!demo |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
516 %! x = 0:10; |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
517 %! subplot (221); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
518 %! plot (x, rand (3, 11)) |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
519 %! ylim ([0, 1]); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
520 %! text (0.5, 0.5, '{x,y}labels & {x,y}ticklabels', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
521 %! 'horizontalalignment', 'center', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
522 %! 'units', 'normalized'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
523 %! xlabel xlabel |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
524 %! ylabel ylabel |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
525 %! title title |
16975 | 526 %! subplot (222); |
527 %! plot (x, rand (3, 11)) | |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
528 %! axis ('labely'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
529 %! ylabel ylabel |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
530 %! text (0.5, 0.5, 'no xlabels, xticklabels', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
531 %! 'horizontalalignment', 'center', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
532 %! 'units', 'normalized'); |
16975 | 533 %! subplot (223); |
534 %! plot (x, rand (3, 11)) | |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
535 %! axis ('labelx'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
536 %! text (0.5, 0.5, 'no ylabels, yticklabels', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
537 %! 'horizontalalignment', 'center', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
538 %! 'units', 'normalized'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
539 %! xlabel xlabel |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
540 %! title title |
16975 | 541 %! subplot (224); |
542 %! plot (x, rand (3, 11)) | |
17012
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
543 %! axis ('nolabel','tic'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
544 %! text (0.5, 0.5, 'no {x,y}labels, {x,y}ticklabels', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
545 %! 'horizontalalignment', 'center', ... |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
546 %! 'units', 'normalized'); |
942d892524b3
Handle alignment of subplots in subplot.m.
Ben Abbott <bpabbott@mac.com>
parents:
16975
diff
changeset
|
547 |
19888
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
548 ## Test recognition/deletion of previous axes |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
549 ## Default mode |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
550 %!test |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
551 %! hf = figure ("visible", "off"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
552 %! unwind_protect |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
553 %! for ii = 1:9 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
554 %! hax(ii) = subplot (3,3,ii); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
555 %! endfor |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
556 %! subplot (3,3,1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
557 %! assert (gca (), hax(1)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
558 %! subplot (2,1,1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
559 %! assert (ishandle (hax),[false(1,6), true(1,3)]); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
560 %! unwind_protect_cleanup |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
561 %! delete (hf); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
562 %! end_unwind_protect |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
563 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
564 ## Position mode |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
565 %!test |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
566 %! hf = figure ("visible", "off"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
567 %! unwind_protect |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
568 %! h1 = subplot ("position", [0.1 0.1 0.3 0.3]); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
569 %! h2 = subplot ("position", [0.5 0.5 0.3 0.3]); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
570 %! subplot ("position", [0.1 0.1 0.3 0.3]); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
571 %! assert (gca (), h1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
572 %! subplot ("position", [0.5 0.5 0.3 0.3]); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
573 %! assert (gca (), h2); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
574 %! subplot ("position", [0.5 0.5 0.3 0.2]); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
575 %! assert (! ishandle (h2)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
576 %! unwind_protect_cleanup |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
577 %! delete (hf); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
578 %! end_unwind_protect |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
579 |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
580 ## Align mode |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
581 %!test |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
582 %! hf = figure ("visible", "off"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
583 %! unwind_protect |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
584 %! h1 = subplot (3,5,1, "align"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
585 %! h2 = subplot (3,5,2, "align"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
586 %! subplot (3,5,1, "align"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
587 %! assert (gca (), h1); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
588 %! subplot (3,2,1, "align"); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
589 %! assert (! ishandle (h1)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
590 %! assert (! ishandle (h2)); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
591 %! unwind_protect_cleanup |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
592 %! delete (hf); |
8064b5cdbc11
subplot.m: fix deletion of previous subplots (bug #41128)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19790
diff
changeset
|
593 %! end_unwind_protect |