2 summary:: Plot numerical data on a window or view
3 categories:: GUI>Accessories
4 related:: Reference/plot
7 Plot data of up to three dimensions on a link::Classes/Window:: or link::Classes/UserView::.
9 subsection:: Keyboard shortcuts
11 When the plotter window has focus, the following keyboard shortcuts can be used to change the display:
13 ## + / - || vertical zoom
14 ## = || compare plot channels
15 ## n || toggle normalize display (0..1) / (-1..1), or fit range
16 ## s || toggle superposition (see: superpose)
17 ## m || switch plot mode (see: link::Classes/Plotter#plotMode::)
18 ## e || toggle editing (see: link::Classes/Plotter#editMode::)
19 ## g || toggle horizontal (domain) grid
20 ## G || toggle vertical (codomain) grid
21 ## ctrl-+ / - || zoom font
22 ## alt-click || post value
25 subsection:: Method extensions
26 Plotter extends other classes with methods. To see what classes implements plot, see link::Overviews/Methods#plot::
32 [1, 6, 2, -5, 2].plot;
33 (0..100).normalize(0, 8pi).sin.plot;
36 { (0..100).normalize(0, 15.0.rand).sin }.dup(3).plot;
37 { { (0..17).normalize(0, 15.0.rand).sin }.dup(4) }.dup(3).plot;
40 { SinOsc.ar([700, 357]) * SinOsc.ar([400, 476]) * 0.2 }.plot;
43 Buffer.read(s, Platform.resourceDir +/+ "sounds/SinedPink.aiff").plot;
46 Env.perc(0.4, 0.6).plot;
49 method:: plotGraph (n,from,to,...)
52 { |x| sin(x) }.plotGraph(300,0,2*pi);
53 { |x| sin(1/x)*x }.plotGraph(from:0.0001,to:0.2);
56 section:: Changing global defaults
58 The default styles are kept (and may be overridden) in code::GUI.skin.at(\plot)::. See also link::Classes/GUI:: help.
61 // specify plot layout
63 GUI.skin.plot.gridLinePattern = FloatArray[1, 0];
64 GUI.skin.plot.fontColor = Color(0.5, 1, 0);
65 GUI.skin.plot.gridColorX = Color.yellow(0.5);
66 GUI.skin.plot.gridColorY = Color.yellow(0.5);
67 GUI.skin.plot.background = Color.black;
68 GUI.skin.plot.plotColor = (10..0).normalize(0.1, 1).collect { |i| Color.rand(i) };
69 GUI.skin.plot.labelX = "X";
70 GUI.skin.plot.labelY = "Y";
74 x = { |i| (0..60).scramble.clump(8) * (3.5 ** i) }.dup(3);
75 x.plot("ARRAY:PLOT", Rect(200, 300, 600, 500));
78 GUI.skin.plot.put(\plotColor, { Color.rand(0.0, 0.8) } ! 8);
79 [(0..100), (20..120), (40..140)].squared.flop.bubble.plot;
81 // reset the defaults:
91 The window bounds (a link::Classes/Rect::).
93 Either a link::Classes/Window:: / link::Classes/View:: may be passed in - then the plot is embedded. Otherwise a new link::Classes/Window:: is created.
97 a = Plotter("the plot", Rect(600, 30, 800, 250));
98 a.value = (0..1000).normalize(0, 14pi).curdle(0.01).scramble.flat.sin;
104 subsection:: Accessing Instance Variables
107 Open given plotter in a new window or within a given composite view.
109 Either a link::Classes/Window:: or link::Classes/View:: may be passed in - then the plot is embedded. Otherwise a new link::Classes/Window:: is created.
111 The window bounds (a link::Classes/Rect::).
114 Set the style of data display.
118 ## code::\linear:: || connecting data points with linear interpolation
119 ## code::\points:: || draw data points only
120 ## code::\plines:: || combination of lines and points
121 ## code::\levels:: || horizontal lines
122 ## code::\steps:: || connecting data points with step interpolation
126 a = (0..20).scramble.plot;
127 a.plotMode = \points; a.refresh;
128 a.plotMode = \plines; a.refresh;
129 a.plotMode = \levels; a.refresh;
130 a.plotMode = \steps; a.refresh;
131 a.plotMode = \linear; a.refresh;
134 method:: setProperties
135 Set properties of all plot views. Defaults are taken from code::GUI.skin.at(\plot);::
137 A list of symbol,value pairs. Supported properties:
143 ## plotColor (an link::Classes/Array::)
146 ## gridLineSmoothing ( link::Classes/Boolean:: )
149 ## gridOnX ( link::Classes/Boolean:: )
150 ## gridOnY ( link::Classes/Boolean:: )
156 a = { (0..30).scramble }.dup(2).plot;
158 \fontColor, Color.red,
159 \plotColor, Color.blue,
160 \backgroundColor, Color.black,
161 \gridColorX, Color.white,
167 GUI.skin.at(\plot); // defaults
171 If the edit mode is set to true, the data may be edited via cursor.
174 a.editMode = true; // now edit the data by clicking into the plot..
175 a.value; // the value
179 Set the number of data points displayed maximally per pixel (default: 1)
181 a = (0..200).scramble.plot;
182 a.resolution = 8; a.refresh; // resizing the window shows interpolation
183 a.resolution = 1; a.refresh;
187 If true (default: code::true::), specs are derived from new data (using min and max values) automatically.
190 If set to true, plotter displays channels on top of each other (keyboard shortcut: s)
192 a = { (0..30).scramble }.dup(2).plot;
193 a.superpose = true; a.refresh;
197 Return or set the data values. Data may be numerical arrays of up to 3 dimensions.
199 a = [1, 4, 2, 7, 4].dup(2).plot;
204 Reference to the current internal data.
207 Returns:: the last cursorPos (a link::Classes/Point::).
210 Returns:: the single subplots (a link::Classes/Plot::).
214 Set or get the spec for the y-axis (codomain).
216 a = { (40..3000).scramble }.dup(2).plot;
217 a.specs = \freq.asSpec; a.refresh;
221 Set or get the spec for the x-axis (domain).
223 a = { (40..300).scramble }.dup(2).plot;
224 a.domainSpecs = \freq.asSpec; a.refresh;
228 Supply a function which is evaluated when editing data. The function is called with the arguments: code::plotter::, code::plotIndex::, code::index::, code::val::, code::x::, code::y::.
233 a = { (0..10).scramble.normalize }.dup(2).plot;
235 a.editFunc = { |...args| args.postln };
238 // using plotter as a control interface
240 a = (0..10).scramble.normalize(300, 400).plot;
241 a.specs = \freq; a.plotMode = \points;
243 x = { SinOsc.ar(\freq.kr(a.value)).mean * 0.1 }.play;
244 a.editFunc = { |plotter, plotIndex, i, val|
245 x.setn(\freq, a.value)
247 a.parent.onClose = { x.release };
251 a = { (0..10).scramble.normalize(300, 400) }.dup.plot;
252 a.specs = \freq; a.plotMode = \levels;
255 var phase = SinOsc.ar(\rate.kr(a.value[1]));
256 SinOsc.ar(\freq.kr(a.value[0]), phase).mean * 0.1
258 a.editFunc = { |plotter, plotIndex, i, val|
259 x.setn(\freq, a.value[0]);
260 x.setn(\rate, a.value[1]);
262 a.parent.onClose = { x.release };
269 // embedding in another GUI
271 w = Window("plot panel", Rect(20, 30, 520, 250));
272 Slider.new(w, Rect(10, 10, 490, 20)).resize_(2).action_ { |v|
273 a.value = (0..(v.value * 80).asInteger).scramble;
276 z = CompositeView(w, Rect(10, 35, 490, 200)).background_(Color.rand(0.7)).resize_(5);
277 a = Plotter("plot", parent: z).value_([0, 1, 2, 3, 4].scramble * 100);
283 a = Plotter("the plot", Rect(600, 30, 600, 400));
284 a.value = (0..100).normalize(0, 8pi).sin;
287 a.value = { |i| (0..90) % (i + 12) + ( (0..90) % (i + 2 * 1) ) }.dup(3);
288 a.value = (0..12).squared;
289 a.plotMode = \points; a.refresh;
290 a.plotMode = \levels; a.refresh;
291 a.plotMode = \plines; a.refresh;
293 a.domainSpecs = [[0, 115, \lin, 1]]; a.refresh;
295 a.parent.close; // close window
296 a.makeWindow; // open it again
298 a.value = { (0..70).scramble }.dup(3);
299 a.plotMode = \linear; a.refresh;
300 a.value = { |i| (0..2000).normalize(0, 4pi + i).sin } ! 4; // lots of values, test efficiency
301 a.value = { |i| (0..10000).normalize(0, 8pi + i).sin } ! 3; // lots of values, test efficiency
302 a.value = { (0..140).scramble } ! 7;
304 a.value = { |i| (0..90).normalize(0, 8pi + (i*2pi)).sin } ! 2 * [400, 560] + 700;
305 a.value = { |i| (_ + 2.0.rand).dup(100).normalize(0, 8pi + i).sin } ! 2 * 400 + 700;
308 // multi channel expansion of single values
309 a.value = { |i| (_ + 2.0.rand).dup(100).normalize(0, 8pi + i).sin *.t [1, 2, 3] } ! 2 * 400 + 700;
310 a.value = { |i| (0..10) **.t [1, 1.2, 1.3, 1.5] * (3.5 ** i) }.dup(3);
312 a.parent.bounds = Rect(400, 100, 500, 700);
313 a.parent.bounds = Rect(600, 30, 500, 300);
316 a.value = { |i| (0..20) * (3.5 ** i) }.dup(5);
321 a.value = (50..90).midicps.scramble;
322 a.specs = \freq; a.refresh;
323 a.value = (1..60).scramble.neg;
324 a.specs = \db; a.refresh;
326 a.value = { |i| { exprand(1e3, (10 ** (i + 8))) }.dup(90) }.dup(3);
327 a.value = { { exprand(1e3, 1e9) }.dup(90) }.dup(3);
328 a.specs = [[1e3, 1e10, \exp], [1e3, 1e20, \exp], [1e3, 1e30, \exp]]; a.refresh;
329 a.domainSpecs = [[0, 5], [-8, 100], [-1, 1]]; a.refresh;
334 a = (4 ** (-5..0)).postln.plot;
335 a.specs = \delay; a.refresh;
336 a.domainSpecs = [0, 10, \lin, 0, 0, " Kg"].asSpec; a.refresh;
339 a.domainSpecs = [0.1, 10, \exponential, 0, 0, " Kg"].asSpec; a.refresh;
340 a.domainSpecs = [-10, 10, \lin, 0, 0, " Kg"].asSpec; a.refresh;
343 a = [(0..100) * 9, (200..1300) * 2, (200..1000)/ 5].plot;
346 a = [[0, 1.2, 1.5], [0, 1.3, 1.5, 1.6], [0, 1.5, 1.8, 2, 6]].midiratio.plot;
347 a.plotMode = \levels; a.refresh;
352 a = { SinOsc.ar([700, 357]) * SinOsc.ar([400, 476]) * 0.2 }.plot;
353 a = { SinOsc.ar([700, 357] *0.02) * SinOsc.ar([400, 476]) * 0.3 }.plot(0.2, minval: -1);
354 a = { SinOsc.ar(440) }.plot(1);
358 Env.perc(0.4, 0.6).plot;
359 Env.new({ 1.0.rand2 }! 8, { 1.0.rand } ! 7, \sin).plot;
362 b = Buffer.read(s, Platform.resourceDir +/+ "sounds/SinedPink.aiff");
363 // Platform.resourceDir +/+ "sounds/SinedPink.aiff" contains SinOsc on left, PinkNoise on right