FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
plot/plotter/example_quartile_test.go at master · zyhong/plot · GitHub
zyhong
plot
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
plot
/
plotter
/
example_quartile_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
122 lines (103 loc) · 2.55 KB
Breadcrumbs
plot
/
plotter
/
example_quartile_test.go
Copy path
File metadata and controls
122 lines (103 loc) · 2.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Copyright ©2015 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
plotter_test
import
(
"log"
"golang.org/x/exp/rand"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg"
)
func
ExampleQuartPlot
() {
rnd
:=
rand
.
New
(
rand
.
NewSource
(
1
))
// Create the example data.
n
:=
100
uniform
:=
make
(plotter.
Values
,
n
)
normal
:=
make
(plotter.
Values
,
n
)
expon
:=
make
(plotter.
Values
,
n
)
for
i
:=
0
;
i
<
n
;
i
++
{
uniform
[
i
]
=
rnd
.
Float64
()
normal
[
i
]
=
rnd
.
NormFloat64
()
expon
[
i
]
=
rnd
.
ExpFloat64
()
}
// Create the QuartPlots
qp1
,
err
:=
plotter
.
NewQuartPlot
(
0
,
uniform
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
qp2
,
err
:=
plotter
.
NewQuartPlot
(
1
,
normal
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
qp3
,
err
:=
plotter
.
NewQuartPlot
(
2
,
expon
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
// Create a vertical plot
p1
,
err
:=
plot
.
New
()
if
err
!=
nil
{
log
.
Panic
(
err
)
}
p1
.
Title
.
Text
=
"Quartile Plot"
p1
.
Y
.
Label
.
Text
=
"plotter.Values"
p1
.
Add
(
qp1
,
qp2
,
qp3
)
// Set the X axis of the plot to nominal with
// the given names for x=0, x=1 and x=2.
p1
.
NominalX
(
"Uniform
\n
Distribution"
,
"Normal
\n
Distribution"
,
"Exponential
\n
Distribution"
)
err
=
p1
.
Save
(
200
,
200
,
"testdata/verticalQuartPlot.png"
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
// Create a horizontal plot
qp1
.
Horizontal
=
true
qp2
.
Horizontal
=
true
qp3
.
Horizontal
=
true
p2
,
err
:=
plot
.
New
()
if
err
!=
nil
{
log
.
Panic
(
err
)
}
p2
.
Title
.
Text
=
"Quartile Plot"
p2
.
X
.
Label
.
Text
=
"plotter.Values"
p2
.
Add
(
qp1
,
qp2
,
qp3
)
// Set the Y axis of the plot to nominal with
// the given names for y=0, y=1 and y=2.
p2
.
NominalY
(
"Uniform
\n
Distribution"
,
"Normal
\n
Distribution"
,
"Exponential
\n
Distribution"
)
err
=
p2
.
Save
(
200
,
200
,
"testdata/horizontalQuartPlot.png"
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
// Now, create a grouped quartile plot.
p3
,
err
:=
plot
.
New
()
if
err
!=
nil
{
log
.
Panic
(
err
)
}
p3
.
Title
.
Text
=
"Box Plot"
p3
.
Y
.
Label
.
Text
=
"plotter.Values"
w
:=
vg
.
Points
(
10
)
for
x
:=
0.0
;
x
<
3.0
;
x
++
{
b0
,
err
:=
plotter
.
NewQuartPlot
(
x
,
uniform
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
b0
.
Offset
=
-
w
b1
,
err
:=
plotter
.
NewQuartPlot
(
x
,
normal
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
b2
,
err
:=
plotter
.
NewQuartPlot
(
x
,
expon
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
b2
.
Offset
=
w
p3
.
Add
(
b0
,
b1
,
b2
)
}
p3
.
Add
(
plotter
.
NewGlyphBoxes
())
p3
.
NominalX
(
"Group 0"
,
"Group 1"
,
"Group 2"
)
err
=
p3
.
Save
(
200
,
200
,
"testdata/groupedQuartPlot.png"
)
if
err
!=
nil
{
log
.
Panic
(
err
)
}
}
Back
|
FazBrowse Home
|
New Git URL