File: Plotter.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 80,296 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (791 lines) | stat: -rw-r--r-- 24,837 bytes parent folder | download | duplicates (2)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
class:: Plotter
summary:: Plot numerical data on a window or view
categories:: GUI>Accessories
related:: Reference/plot


description::
Plot data of up to three dimensions on a link::Classes/Window:: or link::Classes/UserView::.


subsection:: Keyboard shortcuts

When the plotter window has focus, the following keyboard shortcuts can be used to change the display:
table::
## + / - || vertical zoom
## = || compare plot channels
## n || toggle normalize display (0..1) / (-1..1), or fit range
## s || toggle superposition (see: superpose)
## m || switch plot mode (see: link::Classes/Plotter#-plotMode::)
## e || toggle editing (see: link::Classes/Plotter#-editMode::)
## g || toggle horizontal (domain) grid
## G || toggle vertical (codomain) grid
## p || print curve
## ctrl-+ / - || zoom font
## alt-click || post value
::


subsection:: Method extensions
Plotter extends other classes with methods. To see what classes implements plot, see link::Overviews/Methods#plot::


method:: plot (args)

code::
// plot array
[1, 6, 2, -5, 2].plot;
(0..100).normalize(0, 8pi).sin.plot;

// nested arrays
{ (0..100).normalize(0, 15.0.rand).sin }.dup(3).plot;
{ { (0..17).normalize(0, 15.0.rand).sin }.dup(4) }.dup(3).plot;

// UGen functions
{ SinOsc.ar([700, 357]) * SinOsc.ar([400, 476]) * 0.2 }.plot;

// Buffer
{ var b = Buffer.read(s, Platform.resourceDir +/+ "sounds/SinedPink.aiff"); s.sync; b.plot }.fork(AppClock);

// Env
Env.perc(0.4, 0.6).plot;
::


method:: plotGraph (n,from,to,...)

code::
{ |x| sin(x) }.plotGraph(300, 0, 2*pi);
{ |x| sin(1/x) * x }.plotGraph(from: 0.0001, to: 0.2);
::


classmethods::

method:: new
argument:: name
Plot window title.
argument:: bounds
The window bounds (a link::Classes/Rect::).
argument:: parent
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.
discussion::
code::
(
a = Plotter("the plot", Rect(600, 30, 800, 250));
a.value = (0..1000).normalize(0, 14pi).curdle(0.01).scramble.flat.sin;
)
::


instancemethods::


subsection:: Embedding in another view


method:: makeWindow
Open given plotter in a new window or within a given composite view.

See the link::#Embedding in another View or GUI:: example.

argument:: argParent
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.

argument:: argBounds
The window bounds (a link::Classes/Rect::).


subsection:: Plot properties


method:: plotMode
Get/Set the style of data display. This can be an array of different modes for
multi-channel data.
Available modes:
table::
## code::\linear:: || connecting data points with linear interpolation
## code::\points:: || draw data points only
## code::\plines:: || combination of lines and points
## code::\levels:: || horizontal lines
## code::\steps:: || connecting data points with step interpolation
## code::\bars:: || bar graph with filled bars
::

argument:: modes
A link::Classes/Symbol:: or an link::Classes/Array:: of link::Classes/Symbol::s.

If code::modes.size < numChannels::, the plots will emphasis::wrap:: around the
array of modes.

returns::
An link::Classes/Array:: of link::Classes/Symbol::s,
unless there is only one mode specified or if all modes of a multi-channel plot
are the same, in which case a single link::Classes/Symbol:: is returned.

discussion::
code::
a = (0..20).scramble.plot;
a.plotMode = \points; a.refresh;
a.plotMode = \plines; a.refresh;
a.plotMode = \levels; a.refresh;
a.plotMode = \steps; a.refresh;
a.plotMode = \linear; a.refresh;
a.plotMode = \bars; a.refresh;

/* mixed modes */
(
d = 4.collect({ |i| 100.collect({ |j| sinPi(1+i.squared*j * 50.reciprocal) })});
p = d.plot;
p.plotColor_([Color.red, Color.cyan, Color.green, Color.blue]);
p.plotMode_([\steps, \linear, \plines, \points]);
// superpose will trigger a refresh to update colors/modes
p.superpose_(true);
)
::


method:: plotColor
Set or get the colors of your data plot.

argument:: colors
This can be an link::Classes/Array:: of link::Classes/Color::s for
multichannel data, or a single link::Classes/Color:: to map to all channels.

If code::colors.size < numChannels::, the plots will emphasis::wrap:: around the
array of colors.
returns::
An link::Classes/Array:: of link::Classes/Color::s, unless there is only one
color specified or if all colors of a multi-channel plot are the same, in which
case a link::Classes/Color:: is returned.


method:: superpose
If code::true::, plotter displays channels overlaid on a single plot. (keyboard shortcut: s)
code::
a = { (0..30).scramble }.dup(2).plot;
a.superpose = true; a.refresh;
::


method:: axisLabelX
Get/set the label for the x-axes. Can be a link::Classes/String:: or an link::Classes/Array:: of
link::Classes/String::s, or code::nil:: to remove the label.
See link::#Axis labels:: example below.


method:: axisLabelY
Get/set the label for the y-axes. Can be a link::Classes/String:: or an link::Classes/Array:: of
link::Classes/String::s, or code::nil:: to remove the label.
See link::#Axis labels:: example below.


method:: showUnits
Get/set whether the corresponding link::Classes/ControlSpec#-units:: are displayed as labels. The state of link::#-unitLocation:: determines whether the units are shown as axis labels or appended to the tick labels.

argument:: bool
A code::Boolean::.

discussion::
When enabling code::showUnits::, axis or tick labels will only be updated to show the units when the code::axisLabelX/Y:: or grid code::labelAppendString:: properties are code::nil::, empty, or were previously set to show the spec units — i.e. code::showUnits:: won't overwrite a label that has been explicitly set.

See link::#Unit labels:: example below.


method:: unitLocation
Get/set the label type on which the code::Spec:: link::Classes/ControlSpec#-units:: are shown.

See the Discussion in link::#-showUnits:: about the interraction with pre-existing labels at the strong::location::, and link::#Unit labels:: example below.

argument:: location
A code::Symbol::, code::\axis:: or code::\ticks::, to show the units as the axis label or appended to each of the tick labels, respectively.


method:: setProperties
Set properties of all plot views. Defaults are taken from code::GUI.skins.at(\plot);::

warning:: It's preferrable to use Plotter's instance methods when possible
to set Plot properties to ensure proper behavior when using link::#-superpose::.
::

argument:: ... pairs
A list of symbol,value pairs. Supported properties:
list::
## font
## fontColor
## gridColorX
## gridColorY
## plotColor (an link::Classes/Array::)
## backgroundColor
## gridLinePattern
## gridLineSmoothing ( link::Classes/Boolean:: )
## labelX
## labelY
## gridOnX ( link::Classes/Boolean:: )
## gridOnY ( link::Classes/Boolean:: )
::

discussion::
Example:
code::
(
a = { (0..30).scramble }.dup(2).plot;
a.setProperties(
  \fontColor, Color.yellow,
  \plotColor, Color.magenta,
  \backgroundColor, Color.black,
  \gridColorX, Color.green,
  \gridColorY, Color.green,
  \labelX, "Frames",
  \labelFontColor, Color.magenta
);
a.refresh;
);

GUI.skins.at(\plot); // defaults
::


method:: plots

returns:: An link::Classes/Array:: of link::Classes/Plot::s.


subsection:: Grid properties

method:: setGridProperties
Set one or more properties of the code::DrawGridX:: or code::DrawGridY:: used by all code::Plots::.

argument:: axis
A code::Symbol:: denoting the axis whose grid you're modifying: code::\x:: or code::\y::.

argument:: ... propertyPairs
Key value pairs, listed as successive arguments, of the properties to change and their new values. The property key is a code::Symbol::.

Any of setters of code::DrawGridX:: or code::DrawGridY:: can be used. Here is a subset of useful properties:
table::
## code::\labelAnchor:: || A code::Symbol:: denoting the point on the label's bounding link::Classes/Rect:: that anchors to the point where the grid line meets the base of the axis. code::\center, \top, \bottom, \left, \right, \topLeft, \topRight, \bottomLeft, \bottomRight, \leftTop, \rightTop, \leftBottom, \rightBottom::.
## code::\labelOffset:: || A link::Classes/Point:: describing the offset of the code::\labelAnchor:: from the point where the grid line meets the base of the axis. The positive direction for the teletype::x:: and teletype::y:: dimensions is right and down, respectively.
## code::\labelAlign:: || Alignment of the text within its bounding code::Rect::: code::\left::, code::\center::, or code::\right::.
## code::\constrainLabelExtents:: || A code::Boolean:: specifying whether the tick labels at either end of the axis are constrained by, or can extend beyond, the grid bounds.
## code::\drawBaseLine:: || A code::Boolean:: whether a line is drawn at the minimum extent of this strong::axis::.
## code::\drawBoundingLines:: || A code::Boolean:: whether a line is drawn at both ends of the extent of this strong::axis::.
## code::\drawBoundingRect:: || A code::Boolean:: whether a code::Rect:: is drawn around the bounds of the grid area.
## code::\labelAppendString:: || A string to append to all of the axis's tick labels.
## code::\tickSpacing:: || Set the emphasis::minimum:: spacing between grid lines ("ticks") for each axis. See link::Classes/DrawGrid#-tickSpacing:: for details.
## code::\numTicks:: || Set the emphasis::approximate:: number of grid lines ("ticks") for each axis. See link::Classes/DrawGrid#-numTicks:: for details.
## code::\font:: || A link::Classes/Font:: (including size) to be used for the tick labels.
## code::\fontColor:: || The link::Classes/Color:: of the tick labels.
## code::\gridColor:: || The link::Classes/Color:: of the axis grid lines.
::

The properties code::\drawBaseLine::,  code::\drawBoundingLines::, or code::\drawBoundingRect:: are mutually exlusive — setting any of them to true will set the others two to code::false::. In the context of code::Plotter::, setting code::\drawBoundingRect:: on one axis to code::true:: has the same appearance of setting code::\drawBoundingLines:: on emphasis::both:: axes to code::true::.

discussion::
This is a convenience method to set the grid properties for emphasis::all:: code::Plot::s to the same values.
An Example:
code::
(
var plotter = [10, 34, 167].collect({ |freq|
	101.collect{|i| sin((i/1000) * 2pi * freq)}
}).plot;
plotter.setGridProperties(\x,
	\labelAnchor, \topLeft,
	\labelAlign, \left,
	\labelOffset, 1 @ 5,
	\labelAppendString, " samp"
).setGridProperties(\y,
	\labelAnchor, \right,
	\labelAlign, \right,
	\labelOffset, -5 @ 0,
	\constrainLabelExtents, false
)
)
::

To set the properties of grids on each code::Plot:: separately, iterate over the plots:
code::
(
var plotter, labelAnchors;
plotter = [10, 34, 167].collect({ |freq|
	101.collect{|i| sin((i/1000) * 2pi * freq)}
}).plot;

labelAnchors = [\topLeft, \top, \bottomLeft];

plotter.plots.do{ |plot, i|
	plot.drawGrid.x
	.labelAnchor_(labelAnchors[i])
	.constrainLabelExtents_(true);
};
plotter.updatePlotBounds;
)
::


method:: getGridProperty
Get the value of a grid property. See link::#-setGridProperties:: for a list of available properties.

argument:: axis
A code::Symbol:: denoting the axis whose grid you're modifying: code::\x:: or code::\y::.

argument:: property
The property name as a code::Symbol::.

discussion::
As a convenience method, code::getGridProperty:: assumes that properties across all code::Plot::s are the same (as would be the case if set by link::#-setGridProperties::) so returns a single value. Alternatively, properties from individual plot grids can be collected by iterating over the plots:
code::
( // inspect the \labelAnchor of each DrawGridX
var plotter  = [10, 34, 167].collect({ |freq|
	101.collect{|i| sin((i/1000) * 2pi * freq)}
}).plot;

plotter.plots.collect({ |plot|
	plot.drawGrid.x.labelAnchor
}).postln;
)
::


method:: drawGridBoundingRect
Set whether a link::Classes/Rect:: is drawn around the boundary of the grid. Setting to code::false:: disables any bounding grid lines (including "base" lines).

argument:: bool
A code::Boolean::.

discussion::
In some cases, the link::Classes/GridLines:: of the grid will not fall on the minimum or maximum of it's spec's range. Using link::#-drawGridBaseLines:: or link::#-drawGridBoundingRect:: will give the appearance of grid lines at the lower end ("base") of the grid, or at both ends of the grid, respectively.


method:: drawGridBaseLines
Set whether a line is drawn at the lower extent of the grid axes. Setting to code::false:: disables any bounding grid lines (including a bounding code::Rect::). See also the Discussion in link::#-drawGridBoundingRect::.

argument:: bool
A code::Boolean::.


subsection:: Data display properties


method:: specs
Set or get the link::Classes/ControlSpec##spec:: for the y-axis (codomain).

code::
a = { (40..3000).scramble }.dup(2).plot;
a.specs = \freq.asSpec;
::
See also the link::#Explicit domain and axis specs:: example below.


method:: domainSpecs
Set or get the link::Classes/ControlSpec##spec:: for the x-axis (domain).

code::
a = { (40..300).scramble }.dup(2).plot;
a.domainSpecs = \freq.asSpec;
::
See also the link::#Explicit domain and axis specs:: example below.

discussion::
When setting your code::Plotter:: link::#-value::, the default strong::domainSpecs:: is a linear spec in the range code::[0, value.size-1]:: (i.e. the indices of the values). Therefore, your values are displayed as evenly sampled between the code::minval:: and code::maxval::, unless you have explicitly set the link::#-domain:: values.

If a new link::#-value:: is set, you will need to update your domainSpecs.


method:: domain
Set/get the x-axis positions of your data points. The size of the code::domainArray:: must equal the size of your link::#-value:: array, i.e. a domain value specified for each data point.

code::
(
var data, domain, plot;
domain = 25.collect({rrand(0, 50)}).sort;
data = domain.linlin(0, 50, 0, 1);

plot = data.plot.plotMode_(\points);
plot.domainSpecs_([0, 50].asSpec);
plot.domain_(domain);
)
::
See also the link::#Explicit domain and axis specs:: example below.

discussion::
Domain values are mapped into the range of the link::#-domainSpecs::, so need
not be evenly distributed. If link::#-domain:: is set to code::nil::, your
values are displayed as evenly sampled between the code::minval:: and
code::maxval:: of the link::#-domainSpecs::.

Currently, for multichannel data plots, it's assumed that all channels of data
share a single link::#-domain::. I.e. code::domainArray:: must be an
link::Classes/Array:: of rank 1.

If a new link::#-value:: is set, you will need to update your link::#-domain::.


method:: resolution
Set the minimum number of pixels between data points (default: 1)
code::
// Changing plot resolution (x-axis)
p = 5000.collect({ |i| sinPi(i * 0.0025) }).plot;
p.resolution_(5).refresh;  // 5px
p.resolution_(10).refresh;
p.resolution_(50).refresh; // undersampled
p.resolution_(1).refresh;  // default
::


subsection:: Plot data


method:: value
Return or set the data values. Data may be numerical arrays of up to 3 dimensions.
code::
a = [1, 4, 2, 7, 4].dup(2).plot;
a.value;
::


method::setValue
Set the data values, with additional arguments determining how the plot is updated.

argument:: arrays
Arrays of data to plot. Data may be numerical arrays of up to 3 dimensions.

argument:: findSpecs
A code::Boolean::. If code::true:: (default), bounds of the plot(s) are determined automatically.
If code::false::, previous bounds will persist.

argument:: refresh
A code::Boolean::. If code::true:: (default), refresh the view immediately.

argument:: separately
A code::Boolean::. If code::true:: (default), min and max of each set of data will be calculated
and displayed separately for each plot. If code::false::, each plot's range on the
y-axis will be the same.

argument::minval
(Optional) The minimum value displayed on the y-axis.

argument::maxval
(Optional) The maximum value displayed on the y-axis.

argument:: defaultRange
(Optional) A default range for the y-axis in the case
that the max and min values of the data are identical.


method:: findSpecs
If code::true::, specs are derived from new data (using min and max values) automatically. Default: code::true::.


method:: data
Reference to the current internal data (with shape up to depth of 3).


subsection:: Edit mode


method:: editMode
If the edit mode is set to true, the data may be edited via cursor.
code::
a = (0..20).plot;
a.editMode = true; // now edit the data by clicking into the plot..
a.value; // the updated values
::


method:: editFunc
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::.

discussion::
Example:
code::
(
a = { (0..10).scramble.normalize }.dup(2).plot;
a.editMode = true;
a.editFunc = { |...args| args.postln };
)

// using plotter as a control interface
(
a = { (0..10).scramble.normalize(300, 400) }.dup.plot;
a.specs = \freq; a.plotMode = \bars;
a.editMode = true;
x = {
	var phase = SinOsc.ar(\rate.kr(a.value[1]));
	SinOsc.ar(\freq.kr(a.value[0]), phase).mean * 0.1
}.play;
a.editFunc = { |plotter, plotIndex, i, val|
	x.setn(\freq, a.value[0]);
	x.setn(\rate, a.value[1]);
};
a.parent.onClose = { x.release };
)
::


method:: cursorPos

returns:: The last cursorPos (a link::Classes/Point::).


private:: plotColors, prReshape, pointIsInWhichPlot, prSetUpInteractionView


examples::

code::
(
a = Plotter("the plot", Rect(600, 30, 600, 400));
a.value = (0..100).normalize(0, 8pi).sin;
)

a.value = { |i| (0..90) % (i + 12) + ( (0..90) % (i + 2 * 1) ) }.dup(3);
a.value = (0..12).squared;
a.plotMode = \points; a.refresh;
a.plotMode = \levels; a.refresh;
a.plotMode = \plines; a.refresh;

a.domainSpecs = [[0, 115, \lin, 1]]; a.refresh;

a.parent.close; // close window
a.makeWindow; a.updatePlotBounds; // open it again

a.value = { (0..70).scramble }.dup(3);
a.plotMode = \linear; a.refresh;
a.value = { |i| (0..2000).normalize(0, 4pi + i).sin } ! 4; // lots of values, test efficiency
a.value = { |i| (0..10000).normalize(0, 8pi + i).sin } ! 3; // lots of values, test efficiency
a.value = { (0..140).scramble } ! 7;

a.value = { |i| (0..90).normalize(0, 8pi + (i*2pi)).sin } ! 2 * [400, 560] + 700;
a.value = { |i| (_ + 2.0.rand).dup(100).normalize(0, 8pi + i).sin } ! 2 * 400 + 700;


// Multi channel expansion of single values
a.value = { |i| (_ + 2.0.rand).dup(100).normalize(0, 8pi + i).sin *.t [1, 2, 3] } ! 2 * 400 + 700;
a.value = { |i| (0..10) **.t [1, 1.2, 1.3, 1.5] * (3.5 ** i) }.dup(3);

a.parent.bounds = Rect(400, 100, 500, 700);
a.parent.bounds = Rect(600, 30, 500, 300);

a.superpose = true;
a.value = { |i| (0..20) * (3.5 ** i) }.dup(5);
a.superpose = false;
::

subsection:: Object .plot methods

code::

// Array:plot
(
a = (4 ** (-5..0)).postln.plot;
a.specs = \delay; a.refresh;
a.domainSpecs = [0, 10, \lin, 0, 0, " Kg"].asSpec; a.refresh;
);

a.domainSpecs = [0.1, 10, \exponential, 0, 0, " Kg"].asSpec; a.refresh;
a.domainSpecs = [-10, 10, \lin, 0, 0, " Kg"].asSpec; a.refresh;

a = [(0..100) * 9, (200..1300) * 2, (200..1000)/ 5].plot;
a.superpose = true;

a = [[0, 1.2, 1.5], [0, 1.3, 1.5, 1.6], [0, 1.5, 1.8, 2, 6]].midiratio.plot;
a.plotMode = \levels; a.refresh;
a.superpose = false;

// Function:plot
a = { SinOsc.ar([700, 357]) * SinOsc.ar([400, 476]) * 0.2 }.plot;
a = { SinOsc.ar([700, 357] *0.02) * SinOsc.ar([400, 476]) * 0.3 }.plot(0.2, minval: -1);

// Env:plot
Env.perc(0.4, 0.6).plot;
Env.new({ 1.0.rand2 }! 8, { 1.0.rand } ! 7, \sin).plot;

// Buffer:plot
(
s.waitForBoot({
	var b = Buffer.read(s,
		Platform.resourceDir +/+ "sounds/SinedPink.aiff"
	);
	s.sync;
	b.plot;
	b.free;
});
)
::


subsection:: Explicit domain and axis specs
code::
// data
a = (50..90).midicps.scramble.plot;
// specs (y-axis)
a.specs = ControlSpec(100, 2000, units: "Hz"); a.refresh;

a.value = 50.collect{ exprand(1e4, 1e7) };
a.specs = [1e4, 1e7, \exp].asSpec; a.refresh;

// domainSpecs (x-axis)
// If domain is unassigned, values are
// distributed evenly within the spec range
a.domainSpecs = [-10, 70].asSpec; a.refresh;


// Setting the domain, run the full block:
(
var ys, xs; // ys: data, xs: domain positions
var rs = 0, plt2;

// xs are the sample points over a 2pi range

// sample locations, normalized
xs = 50.collect({rrand(0.05, 1)}).normalizeSum;
xs.do{ |me, i| xs[i] = me + rs; rs = rs + me; };

// force beginning/end to land on 0/2pi
xs[0] = 0;
xs[xs.size-1] = 1;

// scale these points to a 2pi range
xs = xs * 2pi;

// ys are the values of the sinusoid at the sampled points
ys = sin(xs);

// the uneven sampling is apparent when
// displayed as uniformly sampled
ys.plot("original data plot, uniform domain", [100, 100, 385, 285].asRect);

// generate a second plot whose domainSpec is specified:
// we see a smooth sinusoid cycle beginning
// at 0 and ending at 2pi
plt2 = ys.plot("resampled domain", [100+400, 100, 385, 285].asRect);

// domain values place plotted points where they
// actually sampled the sinusoid, thus visually
// reconstructing it.
plt2.domain = xs;

// these values are placed within the domainSpec
// so we can pad the plot on either side.
plt2.domainSpecs_(([-0.5pi, 2.5pi]).asSpec);
)

// Non-linear scaling of axes.
// plot 1000 values, linearly distributed on X and Y
p = (1, 2 .. 1000).plot.domainSpecs_([1, 1000, \lin].asSpec).refresh;
// scale y axis exponentially
p.specs_([[1, 1000, \exp].asSpec]).refresh;
// then scale x axis exponentially
p.domainSpecs_([1, 1000, \exp].asSpec).refresh;
::


subsection:: Axis labels

code::
(
p = 4.collect({
	100.collect({ rrand(0,1.0) })
}).plot(bounds: Rect(50,50,500,650));
p.plotColor_([Color.red, Color.blue, Color.green, Color.cyan]);
)

// a single label propagates through all Plots
p.axisLabelX_("one");
// set each individually
p.axisLabelX_(["one", "two", "three", "four"]);
// superposed plots default to the first label
p.superpose_(true);
p.superpose_(false); // labels are restored
// nil element removes a label
p.axisLabelX_(["one", "two", nil, "four"]);
// assigning nil removes all labels
p.axisLabelX_(nil);
// ... axisLabelY behaves the same way
::

subsection:: Unit labels
The units of the grid specs are shown as labels, either axis labels or appended to tick labels. Unit labels won't overwrite preexisting labels, and can be disabled altogether.
code::
( // units displayed in the axis labels by default
p = (4 ** (-1.5, -1.25 .. 0)).plot;
p.specs = \delay.asSpec.minval_(0.1);
p.domainSpecs = [0, 10, \lin, 0, 0, "xUnits"].asSpec;
p.setGridProperties(\y, \constrainLabelExtents, false);
p.setGridProperties(\x, \constrainLabelExtents, true);
)

p.showUnits = false;      // hide units
p.unitLocation = \ticks;  // move units to tick labels
p.showUnits = true;       // show units
p.axisLabelX = "X LABEL"; // set an axis label
p.unitLocation = \axis;   // move units to axes
// ... x-axis label isn't overwritten
p.axisLabelX = nil        // remove x-axis label
p.unitLocation = \axis;   // set units to axes again
// ... units now appear on the x-axis

// customize the Y labels
p.setGridProperties(\y, \labelAppendString, " y");
// move units to tick labels
p.unitLocation = \ticks;
// ... y-axis tick labels aren't overwritten
// now remove y-tick label string
p.setGridProperties(\y, \labelAppendString, nil);
// set units to tick labels again
p.unitLocation = \ticks;
// ... units now appear on the y-tick labels
::

subsection:: Embedding in another View or GUI

code::
(
var w, z, p, d, func;
w = Window("plot panel", Rect(20, 30, 520, 450));
z = CompositeView(
    w, Rect(10, 35, 490, 400)
).background_(Color.rand(0.7)).resize_(5);
p = Plotter("plot", parent: z);
d = Array.rand(32, 0, 20);
func = { |v|
	var offset = v.value.linlin(0, 1, 0, d.size.neg).asInteger;
    p.value = d.rotate(offset).keep(8);
    w.refresh;
};
Slider.new(w, Rect(10, 10, 490, 20)).resize_(2).action_({ |v| func.(v.value) });
func.value(0);
w.front;
)
::


subsection:: Changing global defaults

The default styles are kept (and may be overridden) in code::GUI.skins.at(\plot)::. See also link::Classes/GUI:: help.

code::
// specify plot layout
(
GUI.skins.plot.gridLinePattern = FloatArray[1, 0];
GUI.skins.plot.fontColor = Color(0.5, 1, 0);
GUI.skins.plot.gridColorX = Color.yellow(0.5);
GUI.skins.plot.gridColorY = Color.yellow(0.5);
GUI.skins.plot.background = Color.black;
GUI.skins.plot.plotColor = Color.red;
GUI.skins.plot.labelX = "X";
GUI.skins.plot.labelY = "Y";
)

(
x = { |i| (0..60).scramble * (3.5 ** i) }.dup(3);
x.plot("ARRAY:PLOT", Rect(200, 300, 600, 500));
)

GUI.skins.plot.put(\plotColor, { Color.rand(0.0, 0.8) } ! 8);
[(0..100), (20..120), (40..140)].squared.flop.bubble.plot;

// reset the defaults:
Plot.initClass;
::