FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
plot/plotter/labels_example_test.go at master · devBash99/plot · GitHub
devBash99
/
plot
Public
forked from
gonum/plot
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
plot
/
plotter
/
labels_example_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
106 lines (90 loc) · 2.3 KB
Breadcrumbs
plot
/
plotter
/
labels_example_test.go
Copy path
File metadata and controls
106 lines (90 loc) · 2.3 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
// Copyright ©2020 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"
"os"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
"gonum.org/v1/plot/vg/vgimg"
)
func
ExampleLabels
() {
p
:=
plot
.
New
()
p
.
Title
.
Text
=
"Labels"
p
.
X
.
Min
=
-
10
p
.
X
.
Max
=
+
10
p
.
Y
.
Min
=
0
p
.
Y
.
Max
=
+
20
labels
,
err
:=
plotter
.
NewLabels
(plotter.
XYLabels
{
XYs
: []plotter.
XY
{
{
X
:
-
5
,
Y
:
5
},
{
X
:
+
5
,
Y
:
5
},
{
X
:
+
5
,
Y
:
15
},
{
X
:
-
5
,
Y
:
15
},
},
Labels
: []
string
{
"A"
,
"B"
,
"C"
,
"D"
},
},
)
if
err
!=
nil
{
log
.
Fatalf
(
"could not creates labels plotter: %+v"
,
err
)
}
p
.
Add
(
labels
)
err
=
p
.
Save
(
10
*
vg
.
Centimeter
,
10
*
vg
.
Centimeter
,
"testdata/labels.png"
)
if
err
!=
nil
{
log
.
Fatalf
(
"could save plot: %+v"
,
err
)
}
}
// ExampleLabels_inCanvasCoordinates shows how to write a label
// in a plot using the canvas coordinates (instead of the data coordinates.)
// It can be useful in the situation where one wants to draw some label
// always in the same location of a plot, irrespective of the minute
// details of a particular plot data range.
func
ExampleLabels_inCanvasCoordinates
() {
p
:=
plot
.
New
()
p
.
Title
.
Text
=
"Labels - X"
p
.
X
.
Min
=
-
10
p
.
X
.
Max
=
+
10
p
.
Y
.
Min
=
0
p
.
Y
.
Max
=
+
20
labels
,
err
:=
plotter
.
NewLabels
(plotter.
XYLabels
{
XYs
: []plotter.
XY
{
{
X
:
-
5
,
Y
:
5
},
{
X
:
+
5
,
Y
:
5
},
{
X
:
+
5
,
Y
:
15
},
{
X
:
-
5
,
Y
:
15
},
},
Labels
: []
string
{
"A"
,
"B"
,
"C"
,
"D"
},
},
)
if
err
!=
nil
{
log
.
Fatalf
(
"could not creates labels plotter: %+v"
,
err
)
}
p
.
Add
(
labels
)
f
,
err
:=
os
.
Create
(
"testdata/labels_cnv_coords.png"
)
if
err
!=
nil
{
log
.
Fatalf
(
"could not create output plot file: %+v"
,
err
)
}
defer
f
.
Close
()
cnv
:=
vgimg.
PngCanvas
{
Canvas
:
vgimg
.
New
(
10
*
vg
.
Centimeter
,
10
*
vg
.
Centimeter
),
}
dc
:=
draw
.
New
(
cnv
)
p
.
Draw
(
dc
)
// Put an 'X' in the middle of the data-canvas.
{
fnt
:=
p
.
TextHandler
.
Cache
().
Lookup
(
plotter
.
DefaultFont
,
vg
.
Points
(
12
))
da
:=
p
.
DataCanvas
(
dc
)
da
.
FillString
(
fnt
, vg.
Point
{
X
:
da
.
X
(
0.5
),
Y
:
da
.
Y
(
0.5
)},
"X"
)
}
_
,
err
=
cnv
.
WriteTo
(
f
)
if
err
!=
nil
{
log
.
Fatalf
(
"could not write to output plot file: %+v"
,
err
)
}
err
=
f
.
Close
()
if
err
!=
nil
{
log
.
Fatalf
(
"could save plot: %+v"
,
err
)
}
}
Back
|
FazBrowse Home
|
New Git URL