/usr/share/octave/packages/interval-2.1.0/@infsup/plot.m is in octave-interval 2.1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | ## Copyright 2015-2016 Oliver Heimlich
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @documentencoding UTF-8
## @defmethod {@@infsup} plot (@var{X}, @var{Y})
## @defmethodx {@@infsup} plot (@var{Y})
## @defmethodx {@@infsup} plot (@var{X}, @var{Y}, @var{COLOR})
## @defmethodx {@@infsup} plot (@var{X}, @var{Y}, @var{COLOR}, @var{EDGECOLOR})
##
## Create a 2D-plot of intervals.
##
## If either of @var{X} or @var{Y} is an empty interval, nothing is plotted.
## If both @var{X} and @var{Y} are singleton intervals, a single point is
## plotted. If only one of @var{X} and @var{Y} is a singleton interval, a
## single line is plotted. If neither of @var{X} and @var{Y} is a singleton
## interval, a filled rectangle is plotted.
##
## If @var{X} or @var{Y} are matrices, each pair of elements is plotted
## separately. No connection of the interval areas is plotted, because that
## kind of interpolation would be wrong in general (in the sense that the
## actual values are enclosed by the plot).
##
## Without parameter @var{X}, the intervals in @var{Y} are plotted as points or
## lines, which are parallel to the y axis, at the coordinates
## @code{@var{X} = [1, …, n]}.
##
## If no @var{COLOR} is given, the current @command{colormap} is used. Use
## @var{COLOR} = @option{none} to disable plotting of filled rectangles. If an
## optional parameter @var{EDGECOLOR} is given, rectangles will have visible
## edges in a distinct color.
##
## @end defmethod
## Author: Oliver Heimlich
## Keywords: interval
## Created: 2015-05-10
function plot (x, y, color, edgecolor)
if (nargin > 4)
print_usage ();
return
endif
warning ("off", "interval:ImplicitPromote", "local");
if (not (isa (x, "infsupdec")))
x = infsupdec (x);
endif
if (nargin >= 2 && not (isa (y, "infsupdec")))
y = infsupdec (y);
endif
if (nargin < 2)
y = x;
## x = 1 ... n
x = infsupdec (reshape (1 : numel (y.inf), size (y.inf)));
endif
if (nargin < 3 || isempty (color))
# don't use last row of colormap, which would often be just white
color = colormap ()(ceil (rows (colormap ()) / 2), :);
if (nargin < 4)
# will only be used for lines and dots
edgecolor = colormap ()(1, :);
endif
elseif (nargin < 4)
# will only be used for lines and dots
edgecolor = color;
endif
oldhold = ishold ();
if (not (oldhold))
clf
hold on
endif
pointsize = 3;
edgewidth = 2;
unwind_protect
empty = isempty (x) | isempty (y);
points = issingleton (x) & issingleton (y);
lines = xor (issingleton (x), issingleton (y)) & not (empty);
boxes = not (points | lines | empty);
if (any (points(:)))
scatter (x.inf(points), y.inf(points), ...
pointsize, ...
edgecolor, ...
'filled');
endif
if (any (lines(:)))
x_line = [vec(x.inf(lines)), vec(x.sup(lines))]';
y_line = [vec(y.inf(lines)), vec(y.sup(lines))]';
line (x_line, y_line, ...
'color', edgecolor, ...
'linewidth', edgewidth);
endif
if (any (boxes(:)))
x_box = [vec(x.inf(boxes)), vec(x.sup(boxes))](:, [1 2 2 1])';
y_box = [vec(y.inf(boxes)), vec(y.sup(boxes))](:, [1 1 2 2])';
if (nargin < 4)
edgecolor = 'none';
endif
fill (x_box, y_box, [], ...
'linewidth', edgewidth, ...
'edgecolor', edgecolor, ...
'facecolor', color);
endif
unwind_protect_cleanup
## Reset hold state
if (not (oldhold))
hold off
endif
end_unwind_protect
endfunction
%!# this test is rather pointless
%!test
%! clf
%! plot (empty ());
%! close
%!demo
%! clf
%! hold on
%! plot (infsup (0), infsup (0));
%! plot (infsup (1, 2), infsup (0));
%! plot (infsup (0), infsup (1, 2));
%! plot (infsup (1, 2), infsup (1, 2));
%! axis ([-.5, 2.5, -.5, 2.5]);
%! hold off
%!demo
%! clf
%! plot (infsup (-rand (50, 1), +rand (50, 1)));
%!demo
%! clf
%! hold on
%! axis off
%! range = infsup (0, 9);
%! x = linspace (inf (range), sup (range), 250);
%! X = mince (range, 9);
%! f = @ (x) 0.5 * sin (x) .* x .^ 2;
%! y = f (x);
%! Y = f (X);
%! plot (range, f (range), [42 161 152]/255);
%! plot (X, Y, [238 232 213]/255, [88 110 117]/255);
%! plot (x, y, '-', 'color', [220 50 47]/255, 'linewidth', 2);
%! hold off
|