Mercurial > hg > octave-lyh
annotate scripts/plot/subplot.m @ 14363:f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
* wavread.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m,
asec.m, asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m,
csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, accumarray.m,
accumdim.m, bitcmp.m, bitget.m, bitset.m, blkdiag.m, cart2pol.m, cart2sph.m,
celldisp.m, chop.m, circshift.m, colon.m, common_size.m, cplxpair.m,
cumtrapz.m, curl.m, dblquad.m, deal.m, divergence.m, flipdim.m, fliplr.m,
flipud.m, genvarname.m, gradient.m, idivide.m, int2str.m, interp1.m,
interp1q.m, interp2.m, interp3.m, interpft.m, interpn.m, isa.m, isdir.m,
isequal.m, isequalwithequalnans.m, issquare.m, logspace.m, nargchk.m,
narginchk.m, nargoutchk.m, nextpow2.m, nthargout.m, num2str.m, pol2cart.m,
polyarea.m, postpad.m, prepad.m, profile.m, profshow.m, quadgk.m, quadv.m,
randi.m, rat.m, repmat.m, rot90.m, rotdim.m, shift.m, shiftdim.m, sph2cart.m,
structfun.m, trapz.m, triplequad.m, convhull.m, dsearch.m, dsearchn.m,
griddata3.m, griddatan.m, rectint.m, tsearchn.m, __makeinfo__.m, doc.m,
get_first_help_sentence.m, help.m, type.m, unimplemented.m, which.m, imread.m,
imwrite.m, dlmwrite.m, fileread.m, is_valid_file_id.m, strread.m, textread.m,
textscan.m, commutation_matrix.m, cond.m, condest.m, cross.m,
duplication_matrix.m, expm.m, housh.m, isdefinite.m, ishermitian.m,
issymmetric.m, logm.m, normest.m, null.m, onenormest.m, orth.m, planerot.m,
qzhess.m, rank.m, rref.m, trace.m, vech.m, ans.m, bincoeff.m, bug_report.m,
bzip2.m, comma.m, compare_versions.m, computer.m, edit.m, fileparts.m,
fullfile.m, getfield.m, gzip.m, info.m, inputname.m, isappdata.m, isdeployed.m,
ismac.m, ispc.m, isunix.m, list_primes.m, ls.m, mexext.m, namelengthmax.m,
news.m, orderfields.m, paren.m, recycle.m, rmappdata.m, semicolon.m,
setappdata.m, setfield.m, substruct.m, symvar.m, ver.m, version.m,
warning_ids.m, xor.m, fminbnd.m, fsolve.m, fzero.m, lsqnonneg.m, optimset.m,
pqpnonneg.m, sqp.m, matlabroot.m, __gnuplot_drawnow__.m,
__plt_get_axis_arg__.m, ancestor.m, cla.m, clf.m, close.m, colorbar.m,
colstyle.m, comet3.m, contourc.m, figure.m, gca.m, gcbf.m, gcbo.m, gcf.m,
ginput.m, graphics_toolkit.m, gtext.m, hggroup.m, hist.m, hold.m, isfigure.m,
ishghandle.m, ishold.m, isocolors.m, isonormals.m, isosurface.m, isprop.m,
legend.m, line.m, loglog.m, loglogerr.m, meshgrid.m, ndgrid.m, newplot.m,
orient.m, patch.m, plot3.m, plotyy.m, __print_parse_opts__.m, quiver3.m,
refreshdata.m, ribbon.m, semilogx.m, semilogxerr.m, semilogy.m, stem.m,
stem3.m, subplot.m, title.m, uigetfile.m, view.m, whitebg.m, compan.m, conv.m,
deconv.m, mkpp.m, mpoles.m, pchip.m, poly.m, polyaffine.m, polyder.m,
polyfit.m, polygcd.m, polyint.m, polyout.m, polyval.m, polyvalm.m, ppder.m,
ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, intersect.m,
ismember.m, powerset.m, setdiff.m, setxor.m, union.m, unique.m,
autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m,
fftshift.m, freqz.m, hamming.m, hanning.m, ifftshift.m, sinc.m, sinetone.m,
sinewave.m, unwrap.m, bicg.m, bicgstab.m, gmres.m, gplot.m, nonzeros.m, pcg.m,
pcr.m, spaugment.m, spconvert.m, spdiags.m, speye.m, spfun.m, spones.m,
sprand.m, sprandsym.m, spstats.m, spy.m, svds.m, treelayout.m, bessel.m,
beta.m, betaln.m, factor.m, factorial.m, isprime.m, lcm.m, legendre.m,
nchoosek.m, nthroot.m, perms.m, pow2.m, primes.m, reallog.m, realpow.m,
realsqrt.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, rosser.m,
vander.m, __finish__.m, center.m, cloglog.m, corr.m, cov.m, gls.m, histc.m,
iqr.m, kendall.m, kurtosis.m, logit.m, mahalanobis.m, mean.m, meansq.m,
median.m, mode.m, moment.m, ols.m, ppplot.m, prctile.m, probit.m, quantile.m,
range.m, ranks.m, run_count.m, runlength.m, skewness.m, spearman.m,
statistics.m, std.m, table.m, var.m, zscore.m, betacdf.m, betainv.m, betapdf.m,
betarnd.m, binocdf.m, binoinv.m, binopdf.m, binornd.m, cauchy_cdf.m,
cauchy_inv.m, cauchy_pdf.m, cauchy_rnd.m, chi2cdf.m, chi2inv.m, chi2pdf.m,
chi2rnd.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, discrete_rnd.m,
empirical_cdf.m, empirical_inv.m, empirical_pdf.m, empirical_rnd.m, expcdf.m,
expinv.m, exppdf.m, exprnd.m, fcdf.m, finv.m, fpdf.m, frnd.m, gamcdf.m,
gaminv.m, gampdf.m, gamrnd.m, geocdf.m, geoinv.m, geopdf.m, geornd.m,
hygecdf.m, hygeinv.m, hygepdf.m, hygernd.m, kolmogorov_smirnov_cdf.m,
laplace_cdf.m, laplace_inv.m, laplace_pdf.m, laplace_rnd.m, logistic_cdf.m,
logistic_inv.m, logistic_pdf.m, logistic_rnd.m, logncdf.m, logninv.m,
lognpdf.m, lognrnd.m, nbincdf.m, nbininv.m, nbinpdf.m, nbinrnd.m, normcdf.m,
norminv.m, normpdf.m, normrnd.m, poisscdf.m, poissinv.m, poisspdf.m,
poissrnd.m, stdnormal_cdf.m, stdnormal_inv.m, stdnormal_pdf.m, stdnormal_rnd.m,
tcdf.m, tinv.m, tpdf.m, trnd.m, unidcdf.m, unidinv.m, unidpdf.m, unidrnd.m,
unifcdf.m, unifinv.m, unifpdf.m, unifrnd.m, wblcdf.m, wblinv.m, wblpdf.m,
wblrnd.m, kolmogorov_smirnov_test.m, kruskal_wallis_test.m, base2dec.m,
bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m,
findstr.m, hex2dec.m, index.m, isletter.m, mat2str.m, rindex.m, str2num.m,
strcat.m, strjust.m, strmatch.m, strsplit.m, strtok.m, strtrim.m, strtrunc.m,
substr.m, validatestring.m, demo.m, example.m, fail.m, speed.m, addtodate.m,
asctime.m, clock.m, ctime.m, date.m, datenum.m, datetick.m, datevec.m,
eomday.m, etime.m, is_leap_year.m, now.m:
Use Octave coding conventions in all m-file %!test blocks
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 13 Feb 2012 07:29:44 -0800 |
parents | ce2b59a6d0e5 |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13794
diff
changeset
|
1 ## Copyright (C) 1995-2012 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}) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11305
diff
changeset
|
22 ## Set up a plot grid with @var{rows} by @var{cols} subwindows and plot |
6448 | 23 ## in location given by @var{index}. |
3426 | 24 ## |
3368 | 25 ## If only one argument is supplied, then it must be a three digit value |
26 ## specifying the location in digits 1 (rows) and 2 (columns) and the plot | |
27 ## index in digit 3. | |
3426 | 28 ## |
3368 | 29 ## The plot index runs row-wise. First all the columns in a row are filled |
30 ## and then the next row is filled. | |
3426 | 31 ## |
5798 | 32 ## For example, a plot with 2 by 3 grid will have plot indices running as |
2311 | 33 ## follows: |
3368 | 34 ## @tex |
35 ## \vskip 10pt | |
36 ## \hfil\vbox{\offinterlineskip\hrule | |
37 ## \halign{\vrule#&&\qquad\hfil#\hfil\qquad\vrule\cr | |
7107 | 38 ## height13pt&1&2&3\cr height12pt&&&\cr\noalign{\hrule} |
39 ## height13pt&4&5&6\cr height12pt&&&\cr\noalign{\hrule}}} | |
3368 | 40 ## \hfil |
41 ## \vskip 10pt | |
42 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8350
diff
changeset
|
43 ## @ifnottex |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
44 ## |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
45 ## @example |
3368 | 46 ## @group |
7040 | 47 ## +-----+-----+-----+ |
48 ## | 1 | 2 | 3 | | |
49 ## +-----+-----+-----+ | |
50 ## | 4 | 5 | 6 | | |
51 ## +-----+-----+-----+ | |
8350
0e3a92a8683c
fix texi bug in subplot.m
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8232
diff
changeset
|
52 ## @end group |
6257 | 53 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
54 ## |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
12494
diff
changeset
|
55 ## @var{index} may be a vector. In which case, the new axis will enclose |
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
12494
diff
changeset
|
56 ## the grid locations specified. The first demo illustrates an example: |
12476
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
57 ## |
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
58 ## @example |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 ## demo ("subplot", 1) |
12476
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
60 ## @end example |
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
61 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8350
diff
changeset
|
62 ## @end ifnottex |
12476
070214996fba
subplot.m: Document using INDEX as a vector.
Ben Abbott <bpabbott@mac.com>
parents:
12470
diff
changeset
|
63 ## @seealso{axes, plot} |
3368 | 64 ## @end deftypefn |
1540 | 65 |
2312 | 66 ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU> |
67 ## Adapted-By: jwe | |
1540 | 68 |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
69 function h = subplot (varargin) |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
70 |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
71 align_axes = false; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
72 replace_axes = false; |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
73 have_position = false; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
74 initial_args_decoded = false; |
6163 | 75 |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
76 if (nargin > 2) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
77 ## R, C, N? |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
78 arg1 = varargin{1}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
79 arg2 = varargin{2}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
80 arg3 = varargin{3}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
81 if (isnumeric (arg1) && isscalar (arg1) && isnumeric (arg2) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
82 && isscalar (arg2) && isnumeric (arg3)) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
83 rows = arg1; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
84 cols = arg2; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
85 index = arg3; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
86 varargin(1:3)= []; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
87 initial_args_decoded = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
88 endif |
1540 | 89 endif |
90 | |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
91 if (! initial_args_decoded && nargin > 1) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
92 ## check for 'position', pos, ... |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
93 if (strcmpi (varargin{1}, "position")) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
94 arg = varargin{2}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
95 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
|
96 pos = arg; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
97 varargin(1:2) = []; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
98 have_position = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
99 initial_args_decoded = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
100 else |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
101 error ("expecting position to be a 4-element numeric array"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
102 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
103 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
104 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
105 |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
106 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
|
107 arg = varargin{1}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
108 if (nargin == 1 && ishandle (arg)) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
109 ## Axes handle? |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
110 axes (arg); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
111 cf = get (0, "currentfigure"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
112 set (cf, "nextplot", "add"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
113 return; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
114 elseif (isscalar (arg) && arg >= 0) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
115 ## RCN? |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
116 index = rem (arg, 10); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
117 arg = (arg - index) / 10; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
118 cols = rem (arg, 10); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
119 arg = (arg - cols) / 10; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
120 rows = rem (arg, 10); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
121 varargin(1) = []; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
122 initial_args_decoded = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
123 else |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
124 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
|
125 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
126 endif |
1540 | 127 |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
128 if (! initial_args_decoded) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
129 print_usage (); |
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 |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
132 if (! have_position) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
133 cols = round (cols); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
134 rows = round (rows); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
135 index = round (index); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
136 |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
137 if (any (index < 1) || any (index > rows*cols)) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
138 error ("subplot: INDEX value must be greater than 1 and less than ROWS*COLS"); |
1540 | 139 endif |
140 | |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
141 if (cols < 1 || rows < 1 || index < 1) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
142 error ("subplot: COLS, ROWS, and INDEX must be be positive"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
143 endif |
1540 | 144 endif |
145 | |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
146 nargs = numel (varargin); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
147 while (nargs > 0) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
148 arg = varargin{1}; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
149 if (strcmpi (arg, "align")) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
150 align_axes = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
151 elseif (strcmpi (arg, "replace")) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
152 replace_axes = true; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
153 else |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
154 break; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
155 endif |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
156 varargin(1) = []; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
157 nargs--; |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
158 endwhile |
1540 | 159 |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
160 axesunits = get (0, "defaultaxesunits"); |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
161 cf = gcf (); |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
162 figureunits = get (cf, "units"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
163 unwind_protect |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
164 units = "normalized"; |
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
165 set (0, "defaultaxesunits", units); |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
166 set (cf, "units", "pixels"); |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
167 |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
168 ## 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
|
169 ## which will set "activepositionproperty" to "position". |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
170 ## Τhis can yield to text overlap between labels and titles |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
171 ## see bug #31610 |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
172 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
|
173 align_axes = true; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
174 endif |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
175 |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
176 if (! have_position) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
177 if (align_axes) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
178 pos = subplot_position (rows, cols, index, "position"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
179 elseif (strcmp (get (cf, "__graphics_toolkit__"), "gnuplot")) |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
180 pos = subplot_position (rows, cols, index, "outerpositiontight"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
181 else |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
182 pos = subplot_position (rows, cols, index, "outerposition"); |
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
183 endif |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
184 endif |
1540 | 185 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
186 set (cf, "nextplot", "add"); |
1540 | 187 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
188 found = false; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
189 kids = get (cf, "children"); |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
190 for child = reshape (kids, 1, numel (kids)) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
191 ## Check whether this child is still valid; this might not be the |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
192 ## case anymore due to the deletion of previous children (due to |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
193 ## "deletefcn" callback or for legends/colorbars that are deleted |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
194 ## with their corresponding axes). |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
195 if (! ishandle (child)) |
7086 | 196 continue; |
197 endif | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
198 if (strcmp (get (child, "type"), "axes")) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
199 ## Skip legend and colorbar objects. |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10931
diff
changeset
|
200 if (strcmp (get (child, "tag"), "legend") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10931
diff
changeset
|
201 || strcmp (get (child, "tag"), "colorbar")) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
202 continue; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
203 endif |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
204 if (align_axes) |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
205 objpos = get (child, "position"); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
206 else |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
207 objpos = get (child, "outerposition"); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
208 endif |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
209 if (all (objpos == pos) && ! replace_axes) |
10549 | 210 ## If the new axes are in exactly the same position as an |
211 ## existing axes object, use the existing axes. | |
212 found = true; | |
213 tmp = child; | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
214 else |
10549 | 215 ## If the new axes overlap an old axes object, delete the old |
216 ## axes. | |
217 x0 = pos(1); | |
218 x1 = x0 + pos(3); | |
219 y0 = pos(2); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11576
diff
changeset
|
220 y1 = y0 + pos(4); |
10549 | 221 objx0 = objpos(1); |
222 objx1 = objx0 + objpos(3); | |
223 objy0 = objpos(2); | |
224 objy1 = objy0 + objpos(4); | |
225 if (! (x0 >= objx1 || x1 <= objx0 || y0 >= objy1 || y1 <= objy0)) | |
226 delete (child); | |
227 endif | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
228 endif |
6178 | 229 endif |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
230 endfor |
1540 | 231 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
232 if (found) |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
233 set (cf, "currentaxes", tmp); |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
234 elseif (align_axes) |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
235 tmp = axes ("box", "off", "position", pos, varargin{:}); |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
236 elseif (strcmp (get (cf, "__graphics_toolkit__"), "gnuplot")) |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
237 tmp = axes ("box", "off", "outerposition", pos, varargin{:}); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
238 else |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
239 tmp = axes ("looseinset", [0 0 0 0], "box", "off", "outerposition", pos, |
13794
5b395217ccb9
improve argument parsing for subplot, handle 'position' argument
John W. Eaton <jwe@octave.org>
parents:
12685
diff
changeset
|
240 "autopos_tag", "subplot", varargin{:}); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
241 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
242 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
243 unwind_protect_cleanup |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
244 set (0, "defaultaxesunits", axesunits); |
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
245 set (cf, "units", figureunits); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
246 end_unwind_protect |
1540 | 247 |
6257 | 248 if (nargout > 0) |
249 h = tmp; | |
1540 | 250 endif |
251 | |
252 endfunction | |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
253 |
12470
64ae43e0e1c0
subplot.m: Use new looseinset property introduced by changeset 12467.
Ben Abbott <bpabbott@mac.com>
parents:
12455
diff
changeset
|
254 function pos = subplot_position (rows, cols, index, position_property) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
255 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11305
diff
changeset
|
256 if (rows == 1 && cols == 1) |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
257 ## Trivial result for subplot (1,1,1) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
258 if (strcmpi (position_property, "position")) |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
259 pos = get (0, "defaultaxesposition"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
260 else |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
261 pos = get (0, "defaultaxesouterposition"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
262 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
263 return |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
264 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
265 |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
266 if (strcmp (position_property, "outerposition") |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
267 || strcmp (position_property, "outerpositiontight")) |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
268 margins.left = 0.05; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
269 margins.bottom = 0.05; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
270 margins.right = 0.05; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
271 margins.top = 0.05; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
272 if (strcmp (position_property, "outerpositiontight")) |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
273 margins.column = 0.; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
274 margins.row = 0.; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
275 else |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
276 margins.column = 0.04 / cols; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
277 margins.row = 0.04 / rows; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
278 endif |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
279 width = 1 - margins.left - margins.right - (cols-1)*margins.column; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
280 width = width / cols; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
281 height = 1 - margins.top - margins.bottom - (rows-1)*margins.row; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
282 height = height / rows; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
283 else |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
284 defaultaxesposition = get (0, "defaultaxesposition"); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
285 |
12685
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
286 ## The outer margins surrounding all subplot "positions" are independent |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
287 ## of the number of rows and/or columns |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
288 margins.left = defaultaxesposition(1); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
289 margins.bottom = defaultaxesposition(2); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
290 margins.right = 1.0 - margins.left - defaultaxesposition(3); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
291 margins.top = 1.0 - margins.bottom - defaultaxesposition(4); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
292 |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
293 ## Fit from Matlab experiments |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
294 pc = 1 ./ [0.1860, (margins.left + margins.right - 1)]; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
295 margins.column = 1 ./ polyval (pc , cols); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
296 pr = 1 ./ [0.2282, (margins.top + margins.bottom - 1)]; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
297 margins.row = 1 ./ polyval (pr , rows); |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
298 |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
299 ## Calculate the width/height of the subplot axes "position". |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
300 ## This is also consistent with Matlab |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
301 width = 1 - margins.left - margins.right - (cols-1)*margins.column; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
302 width = width / cols; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
303 height = 1 - margins.top - margins.bottom - (rows-1)*margins.row; |
5cbf660e649d
Restructure subplot positioning and avoid labels overlap (bug #31610)
Konstantinos Poulios <logari81@googlemail.com>
parents:
12575
diff
changeset
|
304 height = height / rows; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
305 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
306 |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
307 ## Index offsets from the lower left subplot |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
308 yi = fix ((index(:)-1)/cols); |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
309 xi = index(:) - yi*cols - 1; |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
310 yi = (rows - 1) - yi; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
311 |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
312 ## Lower left corner of the subplot, i.e. position(1:2) |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
313 x0 = xi .* (width + margins.column) + margins.left; |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
314 y0 = yi .* (height + margins.row) + margins.bottom; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
315 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
316 if (numel(x0) > 1) |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
317 ## subplot (row, col, m:n) |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
318 x1 = max (x0(:)) + width; |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
319 y1 = max (y0(:)) + height; |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
320 x0 = min (x0(:)); |
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
321 y0 = min (y0(:)); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
322 pos = [x0, y0, x1-x0, y1-y0]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
323 else |
12455
7b67bbf9dbbb
subplot.m: Decrease spacing between subplots rows / columns.
Ben Abbott <bpabbott@mac.com>
parents:
12132
diff
changeset
|
324 ## subplot (row, col, num) |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
325 pos = [x0, y0, width, height]; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
326 endif |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
327 |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
328 endfunction |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
329 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
330 |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
331 %!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
|
332 %! clf; |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
333 %! r = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
334 %! c = 3; |
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
335 %! 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
|
336 %! 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
|
337 %! subplot (r, c, n); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
338 %! xlabel (sprintf ('xlabel #%d', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
339 %! ylabel (sprintf ('ylabel #%d', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
340 %! title (sprintf ('title #%d', n)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
341 %! 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
|
342 %! 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
|
343 %! 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
|
344 %! 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
|
345 %! 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
|
346 %! 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
|
347 %! title (sprintf ('title #%d:%d', 1, 3)); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
348 %! 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
|
349 %! axis ([0 1 0 1]); |
8744
4142982c66c6
subplot.m: Compatible placement of subplots.
Ben Abbott <bpabbott@mac.com>
parents:
8517
diff
changeset
|
350 |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
351 %!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
|
352 %! clf; |
11305
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
353 %! x = 0:1; |
c9df571efe95
subplot.m: Add suppport for "align" and "replace" options.
Ben Abbott <bpabbott@mac.com>
parents:
11149
diff
changeset
|
354 %! 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
|
355 %! 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
|
356 %! plot (x, x); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
357 %! 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
|
358 %! 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
|
359 %! 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
|
360 %! end |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14335
diff
changeset
|
361 %! 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
|
362 %! plot (x, x); |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
363 %! xlabel ('xlabel (1,2,1)'); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
364 %! ylabel ('ylabel (1,2,1)'); |
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
365 %! 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
|
366 |