comparison scripts/plot/patch.m @ 14001:5f0bb45e615c

doc: Update documentation for functions returning a graphics handle h (Bug #34761) * voronoi.m, image.m, imagesc.m, imshow.m, area.m, bar.m, barh.m, clabel.m, clf.m, compass.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m, ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m, findall.m, findobj.m, loglog.m, mesh.m, pareto.m, patch.m, pie.m, pie3.m, plot.m, polar.m, quiver.m, quiver3.m, rectangle.m, ribbon.m, rose.m, scatter.m, scatter3.m, semilogx.m, semilogy.m, slice.m, stem.m, surf.m, surface.m, text.m, title.m, trimesh.m, triplot.m, trisurf.m, xlabel.m, ylabel.m, zlabel.m: Update documentation for functions returning a graphics handle h.
author Rik <octave@nomad.inbox5.com>
date Tue, 06 Dec 2011 13:09:17 -0800
parents 240d6810204c
children 72c96de7a403
comparison
equal deleted inserted replaced
14000:15400d5deb1c 14001:5f0bb45e615c
33 ## example, "r" or "red"). 33 ## example, "r" or "red").
34 ## 34 ##
35 ## If passed a structure @var{fv} contain the fields "vertices", "faces" 35 ## If passed a structure @var{fv} contain the fields "vertices", "faces"
36 ## and optionally "facevertexcdata", create the patch based on these 36 ## and optionally "facevertexcdata", create the patch based on these
37 ## properties. 37 ## properties.
38 ##
39 ## The optional return value @var{h} is a graphics handle to the created patch
40 ## object.
41 ## @seealso{fill}
38 ## @end deftypefn 42 ## @end deftypefn
39 43
40 ## Author: jwe 44 ## Author: jwe
41 45
42 function retval = patch (varargin) 46 function retval = patch (varargin)
58 %!demo 62 %!demo
59 %! ## Patches with same number of vertices 63 %! ## Patches with same number of vertices
60 %! clf 64 %! clf
61 %! t1 = (1/16:1/8:1)'*2*pi; 65 %! t1 = (1/16:1/8:1)'*2*pi;
62 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi; 66 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi;
63 %! x1 = sin(t1) - 0.8; 67 %! x1 = sin (t1) - 0.8;
64 %! y1 = cos(t1); 68 %! y1 = cos (t1);
65 %! x2 = sin(t2) + 0.8; 69 %! x2 = sin (t2) + 0.8;
66 %! y2 = cos(t2); 70 %! y2 = cos (t2);
67 %! patch([x1,x2],[y1,y2],'r'); 71 %! patch([x1,x2],[y1,y2],'r');
68 72
69 %!demo 73 %!demo
70 %! ## Unclosed patch 74 %! ## Unclosed patch
71 %! clf 75 %! clf
72 %! t1 = (1/16:1/8:1)'*2*pi; 76 %! t1 = (1/16:1/8:1)'*2*pi;
73 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi; 77 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi;
74 %! x1 = sin(t1) - 0.8; 78 %! x1 = sin (t1) - 0.8;
75 %! y1 = cos(t1); 79 %! y1 = cos (t1);
76 %! x2 = sin(t2) + 0.8; 80 %! x2 = sin (t2) + 0.8;
77 %! y2 = cos(t2); 81 %! y2 = cos (t2);
78 %! patch([[x1;NaN(8,1)],x2],[[y1;NaN(8,1)],y2],'r'); 82 %! patch([[x1;NaN(8,1)],x2],[[y1;NaN(8,1)],y2],'r');
79 83
80 %!demo 84 %!demo
81 %! ## Specify vertices and faces separately 85 %! ## Specify vertices and faces separately
82 %! clf 86 %! clf
83 %! t1 = (1/16:1/8:1)'*2*pi; 87 %! t1 = (1/16:1/8:1)'*2*pi;
84 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi; 88 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi;
85 %! x1 = sin(t1) - 0.8; 89 %! x1 = sin (t1) - 0.8;
86 %! y1 = cos(t1); 90 %! y1 = cos (t1);
87 %! x2 = sin(t2) + 0.8; 91 %! x2 = sin (t2) + 0.8;
88 %! y2 = cos(t2); 92 %! y2 = cos (t2);
89 %! vert = [x1, y1; x2, y2]; 93 %! vert = [x1, y1; x2, y2];
90 %! fac = [1:8,NaN(1,8);9:24]; 94 %! fac = [1:8,NaN(1,8);9:24];
91 %! patch('Faces',fac,'Vertices',vert,'FaceColor','r'); 95 %! patch('Faces',fac,'Vertices',vert,'FaceColor','r');
92 96
93 %!demo 97 %!demo
94 %! ## Specify vertices and faces separately 98 %! ## Specify vertices and faces separately
95 %! clf 99 %! clf
96 %! t1 = (1/16:1/8:1)'*2*pi; 100 %! t1 = (1/16:1/8:1)'*2*pi;
97 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi; 101 %! t2 = ((1/16:1/16:1)' + 1/32)*2*pi;
98 %! x1 = sin(t1) - 0.8; 102 %! x1 = sin (t1) - 0.8;
99 %! y1 = cos(t1); 103 %! y1 = cos (t1);
100 %! x2 = sin(t2) + 0.8; 104 %! x2 = sin (t2) + 0.8;
101 %! y2 = cos(t2); 105 %! y2 = cos (t2);
102 %! vert = [x1, y1; x2, y2]; 106 %! vert = [x1, y1; x2, y2];
103 %! fac = [1:8,NaN(1,8);9:24]; 107 %! fac = [1:8,NaN(1,8);9:24];
104 %! patch('Faces',fac,'Vertices',vert,'FaceVertexCData', [0, 1, 0; 0, 0, 1]); 108 %! patch('Faces',fac,'Vertices',vert,'FaceVertexCData', [0, 1, 0; 0, 0, 1]);
105 109
106 %!demo 110 %!demo
107 %! ## Property change on multiple patches 111 %! ## Property change on multiple patches
108 %! clf 112 %! clf
109 %! t1 = (1/16:1/8:1)'*2*pi; 113 %! t1 = (1/16:1/8:1)'*2*pi;
110 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi; 114 %! t2 = ((1/16:1/8:1)' + 1/32)*2*pi;
111 %! x1 = sin(t1) - 0.8; 115 %! x1 = sin (t1) - 0.8;
112 %! y1 = cos(t1); 116 %! y1 = cos (t1);
113 %! x2 = sin(t2) + 0.8; 117 %! x2 = sin (t2) + 0.8;
114 %! y2 = cos(t2); 118 %! y2 = cos (t2);
115 %! h = patch([x1,x2],[y1,y2],cat (3,[0,0],[1,0],[0,1])); 119 %! h = patch([x1,x2],[y1,y2],cat (3,[0,0],[1,0],[0,1]));
116 %! pause (1); 120 %! pause (1);
117 %! set (h, 'FaceColor', 'r'); 121 %! set (h, 'FaceColor', 'r');
118 122
119 %!demo 123 %!demo
125 %! 0.5, 0.5, 1]; 129 %! 0.5, 0.5, 1];
126 %! faces = [1, 2, 5; 130 %! faces = [1, 2, 5;
127 %! 2, 3, 5; 131 %! 2, 3, 5;
128 %! 3, 4, 5; 132 %! 3, 4, 5;
129 %! 4, 1, 5]; 133 %! 4, 1, 5];
130 %! patch('Vertices', vertices, 'Faces', faces, ... 134 %! patch ('Vertices', vertices, 'Faces', faces, ...
131 %! 'FaceVertexCData', jet(4), 'FaceColor', 'flat') 135 %! 'FaceVertexCData', jet(4), 'FaceColor', 'flat');
132 %! view (-37.5, 30) 136 %! view (-37.5, 30);
133 137
134 %!demo 138 %!demo
135 %! clf 139 %! clf
136 %! vertices = [0, 0, 0; 140 %! vertices = [0, 0, 0;
137 %! 1, 0, 0; 141 %! 1, 0, 0;
140 %! 0.5, 0.5, 1]; 144 %! 0.5, 0.5, 1];
141 %! faces = [1, 2, 5; 145 %! faces = [1, 2, 5;
142 %! 2, 3, 5; 146 %! 2, 3, 5;
143 %! 3, 4, 5; 147 %! 3, 4, 5;
144 %! 4, 1, 5]; 148 %! 4, 1, 5];
145 %! patch('Vertices', vertices, 'Faces', faces, ... 149 %! patch ('Vertices', vertices, 'Faces', faces, ...
146 %! 'FaceVertexCData', jet(5), 'FaceColor', 'interp') 150 %! 'FaceVertexCData', jet(5), 'FaceColor', 'interp');
147 %! view (-37.5, 30) 151 %! view (-37.5, 30);
148 152
149 %!demo 153 %!demo
150 %! clf 154 %! clf
151 %! colormap (jet) 155 %! colormap (jet);
152 %! x = [0 1 1 0]; 156 %! x = [0 1 1 0];
153 %! y = [0 0 1 1]; 157 %! y = [0 0 1 1];
154 %! subplot (2, 1, 1) 158 %! subplot (2, 1, 1);
155 %! title ("Blue, Light-Green, and Red Horizontal Bars") 159 %! title ("Blue, Light-Green, and Red Horizontal Bars");
156 %! patch (x, y + 0, 1); 160 %! patch (x, y + 0, 1);
157 %! patch (x, y + 1, 2); 161 %! patch (x, y + 1, 2);
158 %! patch (x, y + 2, 3); 162 %! patch (x, y + 2, 3);
159 %! subplot (2, 1, 2) 163 %! subplot (2, 1, 2);
160 %! title ("Blue, Light-Green, and Red Vertical Bars") 164 %! title ("Blue, Light-Green, and Red Vertical Bars");
161 %! patch (x + 0, y, 1 * ones (size (x))); 165 %! patch (x + 0, y, 1 * ones (size (x)));
162 %! patch (x + 1, y, 2 * ones (size (x))); 166 %! patch (x + 1, y, 2 * ones (size (x)));
163 %! patch (x + 2, y, 3 * ones (size (x))); 167 %! patch (x + 2, y, 3 * ones (size (x)));
164 168
165 %!demo 169 %!demo
166 %! clf 170 %! clf
167 %! colormap (jet) 171 %! colormap (jet);
168 %! x = [0 1 1 0]; 172 %! x = [0 1 1 0];
169 %! y = [0 0 1 1]; 173 %! y = [0 0 1 1];
170 %! subplot (2, 1, 1) 174 %! subplot (2, 1, 1);
171 %! title ("Blue horizontal bars: Dark to Light") 175 %! title ("Blue horizontal bars: Dark to Light");
172 %! patch (x, y + 0, 1, "cdatamapping", "direct"); 176 %! patch (x, y + 0, 1, "cdatamapping", "direct");
173 %! patch (x, y + 1, 9, "cdatamapping", "direct"); 177 %! patch (x, y + 1, 9, "cdatamapping", "direct");
174 %! patch (x, y + 2, 17, "cdatamapping", "direct"); 178 %! patch (x, y + 2, 17, "cdatamapping", "direct");
175 %! subplot (2, 1, 2) 179 %! subplot (2, 1, 2);
176 %! title ("Blue vertical bars: Dark to Light") 180 %! title ("Blue vertical bars: Dark to Light")
177 %! patch (x + 0, y, 1 * ones (size (x)), "cdatamapping", "direct"); 181 %! patch (x + 0, y, 1 * ones (size (x)), "cdatamapping", "direct");
178 %! patch (x + 1, y, 9 * ones (size (x)), "cdatamapping", "direct"); 182 %! patch (x + 1, y, 9 * ones (size (x)), "cdatamapping", "direct");
179 %! patch (x + 2, y, 17 * ones (size (x)), "cdatamapping", "direct"); 183 %! patch (x + 2, y, 17 * ones (size (x)), "cdatamapping", "direct");
180 184
182 %! clf; 186 %! clf;
183 %! colormap (jet); 187 %! colormap (jet);
184 %! x = [ 0 0; 1 1; 1 0 ]; 188 %! x = [ 0 0; 1 1; 1 0 ];
185 %! y = [ 0 0; 0 1; 1 1 ]; 189 %! y = [ 0 0; 0 1; 1 1 ];
186 %! p = patch (x, y, "facecolor", "b"); 190 %! p = patch (x, y, "facecolor", "b");
187 %! title ("Two blue triangles") 191 %! title ("Two blue triangles");
188 %! set (p, "cdatamapping", "direct", "facecolor", "flat", "cdata", [1 32]) 192 %! set (p, "cdatamapping", "direct", "facecolor", "flat", "cdata", [1 32]);
189 %! title ("Direct mapping of colors: Light-Green UL and Blue LR triangles") 193 %! title ("Direct mapping of colors: Light-Green UL and Blue LR triangles");
190 194
191 %!demo 195 %!demo
192 %! clf; 196 %! clf;
193 %! colormap (jet); 197 %! colormap (jet);
194 %! x = [ 0 0; 1 1; 1 0 ]; 198 %! x = [ 0 0; 1 1; 1 0 ];
195 %! y = [ 0 0; 0 1; 1 1 ]; 199 %! y = [ 0 0; 0 1; 1 1 ];
196 %! p = patch (x, y, [1 32]); 200 %! p = patch (x, y, [1 32]);
197 %! title ("Autoscaling of colors: Red UL and Blue LR triangles") 201 %! title ("Autoscaling of colors: Red UL and Blue LR triangles");
198 202
199 %!test 203 %!test
200 %! hf = figure ("visible", "off"); 204 %! hf = figure ("visible", "off");
201 %! unwind_protect 205 %! unwind_protect
202 %! h = patch; 206 %! h = patch;
203 %! assert (findobj (hf, "type", "patch"), h); 207 %! assert (findobj (hf, "type", "patch"), h);
204 %! assert (get (h, "xdata"), [0; 1; 0], eps); 208 %! assert (get (h, "xdata"), [0; 1; 0], eps);
205 %! assert (get (h, "ydata"), [1; 1; 0], eps); 209 %! assert (get (h, "ydata"), [1; 1; 0], eps);
206 %! assert (isempty(get (h, "zdata"))); 210 %! assert (isempty (get (h, "zdata")));
207 %! assert (isempty(get (h, "cdata"))); 211 %! assert (isempty (get (h, "cdata")));
208 %! assert (get (h, "faces"), [1, 2, 3], eps); 212 %! assert (get (h, "faces"), [1, 2, 3], eps);
209 %! assert (get (h, "vertices"), [0 1; 1 1; 0 0], eps); 213 %! assert (get (h, "vertices"), [0 1; 1 1; 0 0], eps);
210 %! assert (get (h, "type"), "patch"); 214 %! assert (get (h, "type"), "patch");
211 %! assert (get (h, "facecolor"), [0 0 0]); 215 %! assert (get (h, "facecolor"), [0 0 0]);
212 %! assert (get (h, "linestyle"), get (0, "defaultpatchlinestyle")); 216 %! assert (get (h, "linestyle"), get (0, "defaultpatchlinestyle"));
226 %! h = patch ([0 1 0], [0 1 1], 2 * c); 230 %! h = patch ([0 1 0], [0 1 1], 2 * c);
227 %! assert (get (gca, "clim"), [c, 2 * c]); 231 %! assert (get (gca, "clim"), [c, 2 * c]);
228 %! unwind_protect_cleanup 232 %! unwind_protect_cleanup
229 %! close (hf); 233 %! close (hf);
230 %! end_unwind_protect 234 %! end_unwind_protect
235