-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 basic plotting example with axis titles and 3 more ones using scrip…
…t mode (#205)
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module main | ||
|
||
import math | ||
import vsl.plot | ||
|
||
fn main() { | ||
x := []f64{len: 100, init: f64(index) * 0.1} | ||
y1 := x.map(math.sin(it)) | ||
y2 := x.map(math.cos(it)) | ||
|
||
mut plt := plot.Plot.new() | ||
plt.scatter( | ||
x: x | ||
y: y1 | ||
mode: 'lines' | ||
line: plot.Line{ | ||
color: '#FF0000' | ||
} | ||
name: 'sin(x)' | ||
) | ||
plt.scatter( | ||
x: x | ||
y: y2 | ||
mode: 'lines' | ||
line: plot.Line{ | ||
color: '#0000FF' | ||
} | ||
name: 'cos(x)' | ||
) | ||
plt.layout( | ||
title: 'Line Plot with axis titles' | ||
xaxis: plot.Axis { | ||
title: plot.AxisTitle { 'x' } | ||
} | ||
yaxis: plot.Axis { | ||
title: plot.AxisTitle { 'f(x)' } | ||
} | ||
) | ||
plt.show()! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import vsl.plot | ||
import vsl.util | ||
import math | ||
|
||
|
||
f := 60.0 // Hz | ||
beta := 0.5 // rad | ||
a0 := 10 // V | ||
|
||
t := util.lin_space(0, 2*(1/f), 150) // 2 periods | ||
y := t.map(math.sin(2*math.pi*f*it + beta)) // AC signal: y = A₀·sin(2πft + β) | ||
|
||
mut plt := plot.Plot.new() | ||
|
||
plt.scatter( | ||
x: t | ||
y: y | ||
) | ||
|
||
plt.layout( | ||
title: 'AC signal (60Hz)' | ||
xaxis: plot.Axis { | ||
title: plot.AxisTitle { 'time [s]' } | ||
} | ||
yaxis: plot.Axis { | ||
title: plot.AxisTitle { 'amplitude [V]' } | ||
} | ||
) | ||
|
||
plt.show()! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import vsl.plot | ||
import vsl.util | ||
import math | ||
|
||
|
||
t := util.lin_space(-math.pi, math.pi, 50) | ||
y := []f64{len: t.len, init: math.sin(t[index])} | ||
|
||
mut plt := plot.Plot.new() | ||
|
||
plt.scatter( | ||
x: t | ||
y: y | ||
) | ||
|
||
plt.show()! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import vsl.plot | ||
import vsl.util | ||
import math | ||
|
||
|
||
f := 60.0 // Hz | ||
a0 := 100 // V | ||
|
||
t := util.lin_space(0, 2*(1/f), 100) // 2 periods | ||
y1 := t.map(a0*math.sin(2*math.pi*f*it)) // y₁ = A₀·sin(2πft) | ||
y2 := t.map(a0*math.sin(2*math.pi*f*it + 2*math.pi/3)) // y₂ = A₀·sin(2πft + 2π/3) | ||
y3 := t.map(a0*math.sin(2*math.pi*f*it + 4*math.pi/3)) // y₃ = A₀·sin(2πft + 4π/3) | ||
|
||
mut plt := plot.Plot.new() | ||
|
||
plt.scatter( | ||
x: t | ||
y: y1 | ||
name: 'y1(t)' | ||
) | ||
|
||
plt.scatter( | ||
x: t | ||
y: y2 | ||
name: 'y2(t)' | ||
) | ||
|
||
plt.scatter( | ||
x: t | ||
y: y3 | ||
name: 'y3(t)' | ||
) | ||
|
||
plt.layout( | ||
title: 'Three-phase system (60Hz)' | ||
xaxis: plot.Axis { | ||
title: plot.AxisTitle { 'time [s]' } | ||
} | ||
yaxis: plot.Axis { | ||
title: plot.AxisTitle { 'amplitude [V]' } | ||
} | ||
) | ||
|
||
plt.show()! |