comparison scripts/plot/__patch__.m @ 6885:987a7bf45c99

[project @ 2007-09-10 20:51:09 by jwe]
author jwe
date Mon, 10 Sep 2007 20:51:09 +0000
parents 0089a504fdd6
children 1c1d62569590
comparison
equal deleted inserted replaced
6884:1cbb8b606d63 6885:987a7bf45c99
25 25
26 ## Author: Kai Habel 26 ## Author: Kai Habel
27 27
28 function h = __patch__ (p, varargin) 28 function h = __patch__ (p, varargin)
29 29
30 if (nargin < 1) 30 if (nargin < 3)
31 print_usage (); 31 print_usage ();
32 endif 32 endif
33 33
34 nvargs = numel (varargin); 34 iarg = 1;
35 have_x = have_z = have_c = false;
36 if (isnumeric (varargin {1}))
37 if (!isnumeric (varargin {2}))
38 print_usage ();
39 endif
35 40
36 if (nvargs > 1 && isnumeric (varargin{1}) && isnumeric (varargin{2})) 41 x = varargin {1};
37 num_data_args = 2; 42 y = varargin {2};
38 else 43 have_x = true;
39 num_data_args = 0; 44 iarg += 2;
45
46 if (nargin > 3 && ndims (varargin {3}) == 2 &&
47 size (varargin {3}) == size (x))
48 z = varargin {3};
49 have_z = true;
50 iarg ++;
51 endif
40 endif 52 endif
41 53
42 if (rem (nvargs - num_data_args - 1, 2) == 0 && nvargs > 2) 54 if (have_x && nargin > iarg && isnumeric (varargin {iarg}))
43 else 55 c = varargin {iarg};
44 print_usage ("patch"); 56 have_c = true;
57 iarg ++;
58
59 if (ndims (c) == 3 && size (c, 2) == 1)
60 c = permute (c, [1, 3, 2]);
61 endif
45 endif 62 endif
46 63
47 x = varargin{1}; 64 if (rem (nargin - iarg, 2) != 0)
48 y = varargin{2}; 65 print_usage ();
49 c = varargin{3};
50
51 h = __go_patch__ (p);
52 ax = get (h, "parent");
53 if (num_data_args > 1)
54 set (h, "xdata", x, "ydata", y);
55 endif 66 endif
56 67
57 if (isstr (c)) 68 if (have_x)
58 ## Have color string. 69 if (isvector (x))
59 set (h, "FaceColor", c); 70 x = x(:);
60 elseif (length (c) == 1) 71 y = y(:);
61 if (isnan (c)) 72 if (have_z)
62 set (h, "FaceColor", [1, 1, 1]); 73 z = z(:);
63 set (h, "CData", c); 74 endif
64 elseif (isnumeric (c)) 75 endif
65 ## Have color index.
66 set (h, "FaceColor", "flat");
67 set (h, "CData", c);
68 76
69 clim = get(ax, "CLim"); 77 [nr, nc] = size (x);
70 if (c < clim(1)) 78
71 set (ax, "CLim", [c, clim(2)]) 79 for i = 1 : nc
80 h = __go_patch__ (p);
81 ax = get (h, "parent");
82 if (have_x)
83 set (h, "xdata", x (:, i), "ydata", y (:, i));
84 if (have_z)
85 set (h, "zdata", z (:, i));
86 endif
72 endif 87 endif
73 if (c > clim(2))
74 set (ax, "CLim", [clim(1), c])
75 end
76 88
77 else 89 if (have_c)
78 ## Unknown color value. 90 if (ndims (c) == 2 && ((nr > 3 && size (c, 2) == nc) ||
79 error ("color value not valid"); 91 (size (c, 1) > 1 && size (c, 2) == nc)))
80 end 92 c2 = c (:, i);
81 elseif (length (c) == 3) 93 elseif (ndims (c) == 3)
82 ## Have rgb/rgba value. 94 c2 = permute (c (:, i, :), [1, 3, 2]);
83 set (h, "FaceColor", c); 95 else
96 c2 = c;
97 endif
98
99 if (numel (c2) == 1)
100 if (isnan (c))
101 set (h, "FaceColor", [1, 1, 1]);
102 set (h, "CData", c2);
103 elseif (isnumeric (c2))
104 ## Have color index.
105 set (h, "FaceColor", "flat");
106 set (h, "CData", c2);
107 clim = get(ax, "CLim");
108 if (c2 < clim(1))
109 set (ax, "CLim", [c2, clim(2)])
110 endif
111 if (c2 > clim(2))
112 set (ax, "CLim", [clim(1), c2])
113 endif
114 else
115 ## Unknown color value.
116 error ("color value not valid");
117 endif
118 elseif (numel (c2) == 3)
119 ## Have rgb/rgba value.
120 set (h, "FaceColor", c2);
121 else
122 ## Color vector.
123 if (length (c2) != length (x) || length (c2) != length (y))
124 error ("size of x, y, and c must be equal")
125 else
126 set (h, "FaceColor", "interp");
127 set(h, "CData", c2);
128 if (abs(max(c2) - min(c2)) < eps)
129 set (ax, "CLim", [c2(1)-1, c2(1)+1])
130 else
131 set (ax, "CLim", [min(c2), max(c2)]);
132 endif
133 endif
134 endif
135 else
136 set (h, "FaceColor", [0, 1, 0]);
137 endif
138
139 if (nargin > iarg + 1)
140 set (h, varargin{iarg:end});
141 endif
142 endfor
84 else 143 else
85 ## Color vector. 144 error ("Not supported");
86 if (length (c) != length (x) || length (c) != length (y))
87 error ("size of x, y, and c must be equal")
88 else
89 set (h, "FaceColor", "interp");
90 set(h, "CData", c);
91 if (abs(max(c) - min(c)) < eps)
92 set (ax, "CLim", [c(1)-1, c(1)+1])
93 else
94 set (ax, "CLim", [min(c), max(c)]);
95 end
96 end
97 end
98
99 if (nvargs > num_data_args + 1)
100 set (h, varargin{num_data_args+2:end});
101 endif 145 endif
102
103 endfunction 146 endfunction