File: label_plot.m

package info (click to toggle)
plplot 5.10.0%2Bdfsg2-0.4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 25,792 kB
  • ctags: 13,517
  • sloc: ansic: 83,001; xml: 27,081; ada: 18,878; cpp: 15,966; tcl: 11,651; python: 7,075; f90: 7,058; ml: 6,974; java: 6,665; perl: 5,029; sh: 2,208; makefile: 210; lisp: 75; sed: 25; fortran: 7
file content (120 lines) | stat: -rw-r--r-- 3,152 bytes parent folder | download | duplicates (4)
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
## Copyright (C) 1998-2003 Joao Cardoso.
## 
## 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 2 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.
##
## This file is part of plplot_octave.

## function label_plot( data [, label [, class [, names]]])
##
## plot data with point style, marking each point with a number
## indicating the point index in the array data
##
## if label exist, plot each class with a diferent color and symbol
##
## if class exist and is scalar, label only that class
## if class is vector label data(class,:) as points
## if class is matrix label only points such that data == class
##
## if names exists, they will be used at the plot legend
##
## too old, needs to be updated. 

function label_plot( data, label, class, names)

  global __pl
  strm = __pl_init;
  static j;

  set_axis = 0;	# signal that I set the axis
  if (!__pl.axis_st(strm))
    axis([min(data(:,1)), max(data(:,1)), min(data(:,2)), max(data(:,2))]);
    set_axis = 1;
  endif

  margin_st =  plot_margin(1);
  was_hold = 0;
  if (ishold)
    was_hold = 1;
  else
    j=1;
  endif

  [nr, nc] = size (data);

  if (nargin < 2)
    plot(data(:,1), data(:,2),'o');
  else
    if (columns(label) != 1)
      label = label';
      if (columns(label) != 1)
	error("label_plot: `label' must be a vector.\n");
      endif
    endif

    cla = create_set(label);

    if (nargin == 3 && ischar(class))
      names = setstr(ones(max(cla),columns(class))*32);
      t=1;for i=cla; names(i,:) = class(t++,:); endfor
    elseif (nargin <= 3)
      names = setstr(ones(max(cla),4)*32);
      for i=cla; names(i,:) = sprintf(" %2d ", i);end
    endif
    
    for i=cla
      j = rem(j,9)+1; fmt = sprintf("@%d%d;%s;", j-1, j, names(i,:));
      plot(data(find(label==i),1), data(find(label==i),2), fmt);hold on
    endfor
    hold off
  endif

  if (nargin == 3 && isscalar(class))
    item = find(label == class)';
  elseif (nargin == 3 && isvector(class) && columns(class) == 1)
    ## if (columns(class) != 1)
    ##	item = class;
    ## else
    item = class';
    ## endif
  elseif (nargin == 3 && ismatrix(class) && !ischar(class))
    item = []; ct = rows(class);
    if (nc != columns(class))
      error("label_plot: `data' and `class' must have the same number of columns\n");
    endif
    
    for i=1:ct
      [ix, iy] = find(data == ones(nr,1)*class(i,:));
      item = [item, ix(1)]; 
    endfor
  else
    item = 0:-1;
  endif

  hold on
  plot(data(item,1), data(item,2), '95;Erros;'); 
  hold off

  for i = item
    plptex(data(i,1), data(i,2), 0, 0, 0, num2str(i));
  endfor

  if (set_axis) # if I set the axis, I can unset them.
    axis;
  endif

  if (was_hold)
    hold on
  endif

  plflush;pleop;
  plot_margin (margin_st);

endfunction