~ubuntu-branches/debian/sid/octave3.0/sid

« back to all changes in this revision

Viewing changes to scripts/plot/__scatter__.m

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2007-12-23 16:04:15 UTC
  • Revision ID: james.westby@ubuntu.com-20071223160415-n4gk468dihy22e9v
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## Copyright (C) 2007 David Bateman
 
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
 
7
## the Free Software Foundation; either version 3 of the License, or (at
 
8
## your option) any later version.
 
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
 
16
## along with Octave; see the file COPYING.  If not, see
 
17
## <http://www.gnu.org/licenses/>.
 
18
 
 
19
## Undocumented internal function.
 
20
 
 
21
function h = __scatter__ (varargin)
 
22
 
 
23
  h = varargin{1};
 
24
  nd = varargin{2};
 
25
  fcn = varargin{3};
 
26
  x = varargin{4}(:);
 
27
  y = varargin{5}(:);
 
28
  istart = 6;
 
29
 
 
30
  if (nd == 3)
 
31
    z = varargin{6}(:);
 
32
    istart = 7;
 
33
  else
 
34
    z = zeros (length (x), 0);
 
35
  endif
 
36
 
 
37
  firstnonnumeric = Inf;
 
38
  for i = istart:nargin
 
39
    if (! isnumeric (varargin{i}))
 
40
      firstnonnumeric = i;
 
41
      break;
 
42
    endif
 
43
  endfor
 
44
 
 
45
  if (istart < nargin && firstnonnumeric > istart)
 
46
    s = varargin{istart};
 
47
    if (isempty (s))
 
48
      s = 8;
 
49
    endif
 
50
  else
 
51
    s = 8;
 
52
  endif
 
53
  ## Note markersize is in points^2 for 2D and points for 3D, and 
 
54
  ## the below is an approximation, that is empircally visually correct.
 
55
  if (nd == 2)
 
56
    s = sqrt (s) / 2;
 
57
  else
 
58
    s = s / 4;
 
59
  endif
 
60
 
 
61
  if (istart < nargin && firstnonnumeric > istart + 1)
 
62
    c = varargin{istart + 1};
 
63
    if (isvector (c))
 
64
      c = c(:);
 
65
    endif
 
66
  elseif (firstnonnumeric == istart + 1 && ischar (varargin{istart + 1}))
 
67
    c = varargin{istart + 1};
 
68
    firstnonnumeric++;
 
69
  else
 
70
    c = 1 : length(x);
 
71
  endif
 
72
 
 
73
  newargs = {};
 
74
  filled = false;
 
75
  have_marker = false;
 
76
  marker = "o";
 
77
  iarg = firstnonnumeric;
 
78
  while (iarg <= nargin)
 
79
    arg = varargin{iarg++};
 
80
    if (ischar (arg) && strncmp (tolower (arg), "filled", 6))
 
81
      filled = true;
 
82
    elseif ((isstr (arg) || iscell (arg)) && ! have_marker)
 
83
      [linespec, valid] = __pltopt__ ("scatter", arg, false);
 
84
      if (valid)
 
85
        have_marker = true;
 
86
        marker = linespec.marker;
 
87
        if (strncmp (marker, "none", 4))
 
88
          marker = "o";
 
89
        endif
 
90
      else
 
91
        error ("scatter: invalid linespec");
 
92
      endif
 
93
    else
 
94
      newargs{end+1} = arg;
 
95
      if (iarg <= nargin)
 
96
        newargs{end+1} = varagin{iarg++};
 
97
      endif
 
98
    endif
 
99
  endwhile
 
100
 
 
101
  if (ischar (c))
 
102
    h = patch("faces", [1:length(x)].', "vertices", [x, y, z], "facecolor",
 
103
              "none", "edgecolor", c, "marker", marker, 
 
104
              "markersize", s, "linestyle", "none");
 
105
    if (filled)
 
106
      set(h, "markerfacecolor", c); 
 
107
    endif
 
108
  else
 
109
    h = patch("faces", [1:length(x)].', "vertices", [x, y, z], "facecolor",
 
110
              "none", "edgecolor", "flat", "cdata", c, "marker", marker, 
 
111
              "markersize", s, "linestyle", "none");
 
112
    if (filled)
 
113
      set(h, "markerfacecolor", "flat"); 
 
114
    endif
 
115
    ax = get (h, "parent");
 
116
    clim = get (ax, "clim");
 
117
    if (min(c(:)) < clim(1))
 
118
      clim(1) = min(c(:));
 
119
      set (ax, "clim", clim);
 
120
    endif
 
121
    if (max(c(:)) > clim(2))
 
122
      set (ax, "clim", [clim(1), max(c(:))]);
 
123
    endif
 
124
  endif
 
125
 
 
126
endfunction