Skip to content

Commit

Permalink
Merge branch 'main' of github.com:vlang/vsl
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Oct 17, 2023
2 parents b69043e + 3d7569a commit 42ac97c
Show file tree
Hide file tree
Showing 54 changed files with 409 additions and 439 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Made with [contributors-img](https://contrib.rocks).
[deploydocsbadge]: https://github.com/vlang/vsl/actions/workflows/deploy-docs.yml/badge.svg
[licensebadge]: https://img.shields.io/badge/License-MIT-blue.svg
[ModulesBadge]: https://img.shields.io/badge/modules-reference-027d9c?logo=v&logoColor=white&logoWidth=10
[awesomevurl]: https://github.com/vlang/awesome-v/blob/main/README.md#scientific-computing
[awesomevurl]: https://github.com/vlang/awesome-v/blob/master/README.md#scientific-computing
[workflowurl]: https://github.com/vlang/vsl/actions/workflows/ci.yml
[deploydocsurl]: https://github.com/vlang/vsl/actions/workflows/deploy-docs.yml
[licenseurl]: https://github.com/vlang/vsl/blob/main/LICENSE
Expand Down
27 changes: 11 additions & 16 deletions examples/data_analysis_example/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() {
])!

// Visualize data in a 3D scatter plot
mut plt_3d := plot.new_plot()
mut plt_3d := plot.Plot.new()

x1 := data.x.get_col(0)
x2 := data.x.get_col(1)
Expand All @@ -75,7 +75,7 @@ fn main() {
mut x2_class1 := []f64{}

for i in 0 .. data.nb_samples {
if y[i] == 0 {
if y[i] == 0.0 {
x1_class0 << x1[i]
x2_class0 << x2[i]
} else {
Expand All @@ -85,24 +85,21 @@ fn main() {
}

// Add traces for each class in the 3D plot
plt_3d.add_trace(
trace_type: .scatter3d
plt_3d.scatter3d(
x: x1_class0
y: x2_class0
z: []f64{len: x1_class0.len, init: 0.0}
z: [][]f64{len: x1_class0.len, init: [0.0]}
mode: 'markers'
marker: plot.Marker{
size: []f64{len: x1_class0.len, init: 8.0}
color: []string{len: x1_class0.len, init: 'blue'}
}
name: 'Class 0'
)

plt_3d.add_trace(
trace_type: .scatter3d
plt_3d.scatter3d(
x: x1_class1
y: x2_class1
z: []f64{len: x1_class1.len, init: 0.0}
z: [][]f64{len: x1_class1.len, init: [0.0]}
mode: 'markers'
marker: plot.Marker{
size: []f64{len: x1_class1.len, init: 8.0}
Expand All @@ -112,7 +109,7 @@ fn main() {
)

// Configure the layout of the 3D plot
plt_3d.set_layout(
plt_3d.layout(
title: 'Two-class Data'
xaxis: plot.Axis{
title: plot.AxisTitle{
Expand All @@ -134,24 +131,22 @@ fn main() {
stat.update()

// Visualize statistics in a bar chart
mut plt_bars := plot.new_plot()
mut plt_bars := plot.Plot.new()

plt_bars.add_trace(
trace_type: .bar
plt_bars.bar(
x: []string{len: stat.mean_x.len, init: 'Class ${index}'}
y: stat.mean_x
name: 'Mean'
)

plt_bars.add_trace(
trace_type: .bar
plt_bars.bar(
x: []string{len: stat.sig_x.len, init: 'Class ${index}'}
y: stat.sig_x
name: 'Standard Deviation'
)

// Configure the layout of the bar chart
plt_bars.set_layout(
plt_bars.layout(
title: 'Feature Statistics'
)

Expand Down
10 changes: 4 additions & 6 deletions examples/fft_plot_example/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ fn main() {
spectrum := signal.clone()

// Create a scatter plot for the signal and its spectrum
mut plt := plot.new_plot()
mut plt := plot.Plot.new()

// Add a scatter plot for the original signal
plt.add_trace(
trace_type: .scatter
plt.scatter(
x: []f64{len: original_signal.len, init: f64(index)}
y: original_signal
mode: 'markers'
Expand All @@ -37,8 +36,7 @@ fn main() {
)

// Add a scatter plot for the imaginary part of the spectrum
plt.add_trace(
trace_type: .scatter
plt.scatter(
x: []f64{len: spectrum.len, init: f64(index)}
y: spectrum
mode: 'markers'
Expand All @@ -49,7 +47,7 @@ fn main() {
)

// Set up the layout
plt.set_layout(
plt.layout(
title: 'Signal and FFT Spectrum'
)

Expand Down
2 changes: 1 addition & 1 deletion examples/io_h5_dataset/main.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vsl.io.h5
import vsl.inout.h5
import math.stats
import rand

Expand Down
2 changes: 1 addition & 1 deletion examples/io_h5_relax/main.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vsl.io.h5
import vsl.inout.h5
import math

// A simple 1d relaxation problem. Write the results
Expand Down
Empty file.
7 changes: 3 additions & 4 deletions examples/plot_annotated_pie_chart/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ fn main() {
labels := ['Apples', 'Bananas', 'Cherries', 'Grapes']
values := [25.0, 30, 15, 30]

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .pie
mut plt := plot.Plot.new()
plt.pie(
labels: labels
values: values
textinfo: 'percent+label'
)
plt.set_layout(
plt.layout(
title: 'Pie Chart with Annotations'
)
plt.show()!
Expand Down
7 changes: 3 additions & 4 deletions examples/plot_bar/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ module main
import vsl.plot

fn main() {
mut plt := plot.new_plot()
mut plt := plot.Plot.new()

plt.add_trace(
trace_type: .bar
plt.bar(
x: ['China', 'India', 'USA', 'Indonesia', 'Pakistan']
y: [1411778724.0, 1379217184, 331989449, 271350000, 225200000]
)
plt.set_layout(
plt.layout(
title: 'Countries by population'
)
plt.show()!
Expand Down
9 changes: 4 additions & 5 deletions examples/plot_basic_heatmap/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ z := [[1.0, 0, 30, 50, 1], [20.0, 1, 60, 80, 30], [30.0, 60, 1, -10, 20]]
x := ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
y := ['Morning', 'Afternoon', 'Evening']

mut plt := plot.new_plot()
mut plt := plot.Plot.new()

plt.add_trace(
trace_type: .heatmap
plt.heatmap(
x: x
y_str: y
y: y
z: z
)
plt.set_layout(
plt.layout(
title: 'Heatmap Basic Implementation'
width: 750
height: 750
Expand Down
7 changes: 3 additions & 4 deletions examples/plot_bubble_chart/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ fn main() {
y := []f64{len: 100, init: f64(index) * 0.1}
size := []f64{len: 10, init: f64(index) * 10.0}

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .scatter
mut plt := plot.Plot.new()
plt.scatter(
x: x
y: y
mode: 'markers'
Expand All @@ -19,7 +18,7 @@ fn main() {
}
name: 'Bubble Chart'
)
plt.set_layout(
plt.layout(
title: 'Bubble Chart'
)
plt.show()!
Expand Down
10 changes: 4 additions & 6 deletions examples/plot_grouped_bar_chart/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ fn main() {
values1 := [10.0, 15, 7, 12]
values2 := [8.0, 14, 5, 10]

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .bar
mut plt := plot.Plot.new()
plt.bar(
x: categories
y: values1
name: 'Group 1'
)
plt.add_trace(
trace_type: .bar
plt.bar(
x: categories
y: values2
name: 'Group 2'
)
plt.set_layout(
plt.layout(
title: 'Grouped Bar Chart'
)
plt.show()!
Expand Down
7 changes: 3 additions & 4 deletions examples/plot_heatmap_golden_ratio/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ z := [[13.0, 3, 3, 5], [13.0, 2, 1, 5], [13.0, 10, 11, 12], [13.0, 8, 8, 8]]
// x := r*math.cos(theta)
// y := r*math.sin(theta)

mut plt := plot.new_plot()
mut plt := plot.Plot.new()

plt.add_trace(
trace_type: .heatmap
plt.heatmap(
x: xe
y: ye
z: z
)
plt.set_layout(
plt.layout(
title: 'Heatmap with Unequal Block Sizes'
width: 750
height: 750
Expand Down
23 changes: 10 additions & 13 deletions examples/plot_histogram/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import vsl.plot

rand.seed([u32(1), 42])

mut x1 := []f64{cap: 1000}
for _ in 1 .. 1000 {
x1 << rand.f64n(100) or { 0 }
}
mut plt := plot.new_plot()
plt.add_trace(
trace_type: .histogram
x: x1
xbins: {
'start': f32(0)
'end': f32(100)
'size': 2
x := []f64{len: 1000, init: (0 * index) + rand.f64n(100) or { 0 }}

mut plt := plot.Plot.new()
plt.histogram(
x: x
xbins: plot.Bins{
start: 0.0
end: 100.0
size: 2
}
)
plt.set_layout(
plt.layout(
title: 'Histogram Example'
width: 750
height: 750
Expand Down
10 changes: 4 additions & 6 deletions examples/plot_line_plot_with_areas/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ fn main() {
y1 := x.map(math.sin(it))
y2 := x.map(math.cos(it))

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .scatter
mut plt := plot.Plot.new()
plt.scatter(
x: x
y: y1
mode: 'lines'
Expand All @@ -19,8 +18,7 @@ fn main() {
}
name: 'sin(x)'
)
plt.add_trace(
trace_type: .scatter
plt.scatter(
x: x
y: y2
mode: 'lines'
Expand All @@ -29,7 +27,7 @@ fn main() {
}
name: 'cos(x)'
)
plt.set_layout(
plt.layout(
title: 'Line Plot with Highlighted Areas'
)
plt.show()!
Expand Down
29 changes: 15 additions & 14 deletions examples/plot_pie/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ module main

import vsl.plot

mut plt := plot.new_plot()
fn main() {
mut plt := plot.Plot.new()

plt.add_trace(
trace_type: .pie
labels: ['Nitrogen', 'Oxygen', 'Argon', 'Other']
values: [78.0, 21, 0.9, 0.1]
pull: [0.0, 0.1, 0, 0]
hole: 0.25
)
plt.set_layout(
title: 'Gases in the atmosphere'
width: 750
height: 750
)
plt.show()!
plt.pie(
labels: ['Nitrogen', 'Oxygen', 'Argon', 'Other']
values: [78.0, 21, 0.9, 0.1]
pull: [0.0, 0.1, 0, 0]
hole: 0.25
)
plt.layout(
title: 'Gases in the atmosphere'
width: 750
height: 750
)
plt.show()!
}
7 changes: 3 additions & 4 deletions examples/plot_ripple_surface/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ fn main() {
z << row
}

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .surface
mut plt := plot.Plot.new()
plt.surface(
x: x
y: y
z: z
colorscale: 'Viridis'
)
plt.set_layout(
plt.layout(
title: 'Ripple Effect Surface'
)
plt.show()!
Expand Down
7 changes: 3 additions & 4 deletions examples/plot_saddle_surface/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ fn main() {
z << row
}

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .surface
mut plt := plot.Plot.new()
plt.surface(
x: x
y: y
z: z
colorscale: 'Viridis'
)
plt.set_layout(
plt.layout(
title: 'Saddle Surface'
)
plt.show()!
Expand Down
Loading

0 comments on commit 42ac97c

Please sign in to comment.