Skip to content

Commit

Permalink
chore: Update plot examples with axis titles and script mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Jun 9, 2024
1 parent 91a3e7b commit 60954e6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
8 changes: 4 additions & 4 deletions examples/plot_line_axis_titles/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ fn main() {
)
plt.layout(
title: 'Line Plot with axis titles'
xaxis: plot.Axis {
title: plot.AxisTitle { 'x' }
xaxis: plot.Axis{
title: plot.AxisTitle{'x'}
}
yaxis: plot.Axis {
title: plot.AxisTitle { 'f(x)' }
yaxis: plot.Axis{
title: plot.AxisTitle{'f(x)'}
}
)
plt.show()!
Expand Down
21 changes: 10 additions & 11 deletions examples/script_mode_ac_signal/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import vsl.plot
import vsl.util
import math

f := 60.0 // Hz
beta := 0.5 // rad
a0 := 10 // V

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 + β)
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()

Expand All @@ -19,12 +18,12 @@ plt.scatter(

plt.layout(
title: 'AC signal (60Hz)'
xaxis: plot.Axis {
title: plot.AxisTitle { 'time [s]' }
xaxis: plot.Axis{
title: plot.AxisTitle{'time [s]'}
}
yaxis: plot.Axis {
title: plot.AxisTitle { 'amplitude [V]' }
yaxis: plot.Axis{
title: plot.AxisTitle{'amplitude [V]'}
}
)

plt.show()!
plt.show()!
3 changes: 1 addition & 2 deletions examples/script_mode_simple_plot/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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])}

Expand All @@ -13,4 +12,4 @@ plt.scatter(
y: y
)

plt.show()!
plt.show()!
23 changes: 11 additions & 12 deletions examples/script_mode_three_phase_signal/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import vsl.plot
import vsl.util
import math

f := 60.0 // Hz
a0 := 100 // V

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)
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()

Expand All @@ -33,12 +32,12 @@ plt.scatter(

plt.layout(
title: 'Three-phase system (60Hz)'
xaxis: plot.Axis {
title: plot.AxisTitle { 'time [s]' }
xaxis: plot.Axis{
title: plot.AxisTitle{'time [s]'}
}
yaxis: plot.Axis {
title: plot.AxisTitle { 'amplitude [V]' }
yaxis: plot.Axis{
title: plot.AxisTitle{'amplitude [V]'}
}
)

plt.show()!
plt.show()!

0 comments on commit 60954e6

Please sign in to comment.