comparison scripts/plot/stem.m @ 17432:77bec442a35a

Overhaul stem family of plot functions. * scripts/plot/private/__stem__.m: Use low-level plotting fcn __line__ for performance. Add property/listener on 'basevalue' for baseline object. Simplify and correct input option processing so that it actually does the right thing. * scripts/plot/stem.m: Add list of "stem series" properties to docstring. Add titles to %!demos. Add %!error tests for input validation. * scripts/plot/stem3.m: Cross-reference "stem series" to stem documentation. Accept property/value pair inputs. Add %!error tests for input validation.
author Rik <rik@octave.org>
date Wed, 18 Sep 2013 10:32:27 -0700
parents bc924baa2c4e
children fedcd3717ebc
comparison
equal deleted inserted replaced
17431:1dfc3abb0f0d 17432:77bec442a35a
55 ## of the plot. 55 ## of the plot.
56 ## 56 ##
57 ## If the first argument @var{hax} is an axes handle, then plot into this axis, 57 ## If the first argument @var{hax} is an axes handle, then plot into this axis,
58 ## rather than the current axes returned by @code{gca}. 58 ## rather than the current axes returned by @code{gca}.
59 ## 59 ##
60 ## The optional return value @var{h} is a vector of "stem series" graphics 60 ## The optional return value @var{h} is a handle to a "stem series" hggroup.
61 ## handles with one handle per column of the variable @var{y}. The 61 ## The single hggroup handle has all of the graphical elements comprising the
62 ## handle regroups the elements of the stem graph together as the 62 ## plot as its children; This allows the properties of multiple graphics
63 ## children of the "stem series" handle, allowing them to be altered 63 ## objects to be changed by modifying just a single property of the
64 ## together. For example, 64 ## "stem series" hggroup.
65 ##
66 ## For example,
65 ## 67 ##
66 ## @example 68 ## @example
67 ## @group 69 ## @group
68 ## x = [0:10]'; 70 ## x = [0:10]';
69 ## y = [sin(x), cos(x)] 71 ## y = [sin(x), cos(x)]
74 ## @end example 76 ## @end example
75 ## 77 ##
76 ## @noindent 78 ## @noindent
77 ## changes the color of the second "stem series" and moves the base line 79 ## changes the color of the second "stem series" and moves the base line
78 ## of the first. 80 ## of the first.
81 ##
82 ## Stem Series Properties
83 ##
84 ## @table @asis
85 ## @item linestyle
86 ## The linestyle of the stem. (Default: @qcode{"-"})
87 ##
88 ## @item linewidth
89 ## The width of the stem. (Default: 0.5)
90 ##
91 ## @item color
92 ## The color of the stem, and if not separately specified, the marker.
93 ## (Default: "b" [blue])
94 ##
95 ## @item marker
96 ## The marker symbol to use at the top of each stem. (Default: @qcode{"o"})
97 ##
98 ## @item markeredgecolor
99 ## The edge color of the marker. (Default: @qcode{"color"} property)
100 ##
101 ## @item markerfacecolor
102 ## The color to use for "filling" the marker. (Default: @qcode{"none"}
103 ## [unfilled])
104 ##
105 ## @item markersize
106 ## The size of the marker. (Default: 6)
107 ##
108 ## @item baseline
109 ## The handle of the line object which implements the baseline. Use @code{set}
110 ## with the returned handle to change graphic properties of the baseline.
111 ##
112 ## @item basevalue
113 ## The y-value where the baseline is drawn. (Default: 0)
114 ## @end table
79 ## @seealso{stem3, bar, hist, plot, stairs} 115 ## @seealso{stem3, bar, hist, plot, stairs}
80 ## @end deftypefn 116 ## @end deftypefn
81 117
82 ## Author: Michel D. Schmid <michaelschmid@users.sourceforge.net> 118 ## Author: Michel D. Schmid <michaelschmid@users.sourceforge.net>
83 ## Adapted-by: jwe 119 ## Adapted-by: jwe
97 endfunction 133 endfunction
98 134
99 135
100 %!demo 136 %!demo
101 %! clf; 137 %! clf;
102 %! x = 1:10; 138 %! y = 1:10;
103 %! stem (x); 139 %! stem (y);
140 %! title ('stem plot of y-values only');
104 141
105 %!demo 142 %!demo
106 %! clf; 143 %! clf;
107 %! x = 1:10; 144 %! x = 1:10;
108 %! y = 2*x; 145 %! y = 2*x;
109 %! stem (x, y); 146 %! stem (x, y);
147 %! title ('stem plot of x and y-values');
110 148
111 %!demo 149 %!demo
112 %! clf; 150 %! clf;
113 %! x = 1:10; 151 %! x = 1:10;
114 %! y = 2*x; 152 %! y = 2*x;
115 %! h = stem (x, y, 'r'); 153 %! h = stem (x, y, 'r');
154 %! title ('stem plot with modified color');
116 155
117 %!demo 156 %!demo
118 %! clf; 157 %! clf;
119 %! x = 1:10; 158 %! x = 1:10;
120 %! y = 2*x; 159 %! y = 2*x;
121 %! h = stem (x, y, '-.k'); 160 %! h = stem (x, y, '-.k');
122 161 %! title ('stem plot with modified line style and color');
123 %!demo 162
124 %! clf; 163 %!demo
125 %! x = 1:10; 164 %! clf;
126 %! y = 2*x; 165 %! x = 1:10;
127 %! h = stem (x, y, '-.k.'); 166 %! y = 2*x;
167 %! h = stem (x, y, '-.ks');
168 %! title ('stem plot with modified line style, color, and marker');
128 169
129 %!demo 170 %!demo
130 %! clf; 171 %! clf;
131 %! x = 1:10; 172 %! x = 1:10;
132 %! y = 2*x; 173 %! y = 2*x;
133 %! h = stem (x, y, 'filled'); 174 %! h = stem (x, y, 'filled');
175 %! title ('stem plot with "filled" markers');
176
177 %!demo
178 %! clf;
179 %! x = 1:10;
180 %! y = 2*x;
181 %! h = stem (x, y, 'markerfacecolor', [1 0 1]);
182 %! title ('stem plot modified with property/value pair');
134 183
135 %!demo 184 %!demo
136 %! clf; 185 %! clf;
137 %! x = (0 : 10)'; 186 %! x = (0 : 10)';
138 %! y = [sin(x), cos(x)]; 187 %! y = [sin(x), cos(x)];
139 %! h = stem (x, y); 188 %! h = stem (x, y);
140 %! set (h(2), 'color', 'g'); 189 %! set (h(2), 'color', 'g');
141 %! set (h(1), 'basevalue', -1); 190 %! set (h(1), 'basevalue', -1);
191 %! title ('stem plots modified through hggroup handle');
142 192
143 %!demo 193 %!demo
144 %! clf; 194 %! clf;
145 %! N = 11; 195 %! N = 11;
146 %! x = 0:(N-1); 196 %! x = 0:(N-1);
147 %! y = rand (1, N); 197 %! y = rand (1, N);
148 %! hs = stem (x(1), y(1)); 198 %! hs = stem (x(1), y(1));
149 %! set (gca (), 'xlim', [1, N-1], 'ylim', [0, 1]); 199 %! set (gca (), 'xlim', [1, N-1], 'ylim', [0, 1]);
200 %! title ('stem plot data modified through hggroup handle');
150 %! for k=2:N 201 %! for k=2:N
151 %! set (hs, 'xdata', x(1:k), 'ydata', y(1:k)) 202 %! set (hs, 'xdata', x(1:k), 'ydata', y(1:k))
152 %! drawnow (); 203 %! drawnow ();
153 %! pause (0.2); 204 %! pause (0.2);
154 %! end 205 %! end
155 206
207 %!error stem ()
208 %!error <can not define Z for 2-D stem plot> stem (1,2,3)
209 %!error <X and Y must be numeric> stem ({1})
210 %!error <X and Y must be numeric> stem (1, {1})
211 %!error <inconsistent sizes for X and Y> stem (1:2, 1:3)
212 %!error <inconsistent sizes for X and Y> stem (1:2, ones (3,3))
213 %!error <inconsistent sizes for X and Y> stem (ones (2,2), ones (3,3))
214 %!error <No value specified for property "FOO"> stem (1, "FOO")
215