Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing python for vsl.plot - WIP #173

Merged
merged 12 commits into from
Oct 17, 2023
23 changes: 9 additions & 14 deletions examples/data_analysis_example/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -136,22 +133,20 @@ fn main() {
// Visualize statistics in a bar chart
mut plt_bars := plot.new_plot()

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
8 changes: 3 additions & 5 deletions examples/fft_plot_example/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ fn main() {
mut plt := plot.new_plot()

// 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
5 changes: 2 additions & 3 deletions examples/plot_annotated_pie_chart/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ fn main() {
values := [25.0, 30, 15, 30]

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

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
5 changes: 2 additions & 3 deletions examples/plot_basic_heatmap/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ y := ['Morning', 'Afternoon', 'Evening']

mut plt := plot.new_plot()

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

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .scatter
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
8 changes: 3 additions & 5 deletions examples/plot_grouped_bar_chart/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ fn main() {
values2 := [8.0, 14, 5, 10]

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .bar
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
5 changes: 2 additions & 3 deletions examples/plot_heatmap_golden_ratio/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ z := [[13.0, 3, 3, 5], [13.0, 2, 1, 5], [13.0, 10, 11, 12], [13.0, 8, 8, 8]]

mut plt := plot.new_plot()

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
5 changes: 2 additions & 3 deletions examples/plot_histogram/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ for _ in 1 .. 1000 {
x1 << rand.f64n(100) or { 0 }
}
mut plt := plot.new_plot()
plt.add_trace(
trace_type: .histogram
plt.histogram(
x: x1
xbins: {
'start': f32(0)
'end': f32(100)
'size': 2
}
)
plt.set_layout(
plt.layout(
title: 'Histogram Example'
width: 750
height: 750
Expand Down
8 changes: 3 additions & 5 deletions examples/plot_line_plot_with_areas/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ fn main() {
y2 := x.map(math.cos(it))

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .scatter
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement is not updated to reflect the new module name plotly. It should be import vsl.plotly instead of import vsl.plot.

- import vsl.plot
+ import vsl.plotly


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

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()!
}
5 changes: 2 additions & 3 deletions examples/plot_ripple_surface/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ fn main() {
}

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

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .surface
plt.surface(
x: x
y: y
z: z
colorscale: 'Viridis'
)
plt.set_layout(
plt.layout(
title: 'Saddle Surface'
)
plt.show()!
ulises-jeremias marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 2 additions & 3 deletions examples/plot_scatter/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ y := [
x := util.arange(y.len).map(f64(it))

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .scatter
plt.scatter(
x: x
y: y
mode: 'lines+markers'
Expand All @@ -34,7 +33,7 @@ plt.add_trace(
color: '#FF0000'
}
)
plt.set_layout(
plt.layout(
title: 'Scatter plot example'
)
plt.show()!
5 changes: 2 additions & 3 deletions examples/plot_scatter3d_1/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ fn main() {
z := util.arange(y.len).map(util.arange(y.len).map(f64(it * it)))

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .scatter3d
plt.scatter3d(
x: x
y: y
z: z
Expand All @@ -37,7 +36,7 @@ fn main() {
color: '#0000FF'
}
)
plt.set_layout(
plt.layout(
title: 'Scatter plot example'
)
plt.show()!
Expand Down
5 changes: 2 additions & 3 deletions examples/plot_scatter3d_2/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ fn main() {
}

mut plt := plot.new_plot()
plt.add_trace(
trace_type: .scatter3d
plt.scatter3d(
x: x
y: y
z: z
Expand All @@ -27,7 +26,7 @@ fn main() {
color: []string{len: x.len, init: '#0000FF'}
}
)
plt.set_layout(
plt.layout(
title: 'Scatter plot example'
)
plt.show()!
Expand Down
5 changes: 2 additions & 3 deletions examples/plot_scatter3d_easing/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ fn main() {

// Create the Scatter3D plot
mut plt := plot.new_plot()
plt.add_trace(
plt.scatter3d(
name: 'Easing Scatter3D'
trace_type: .scatter3d
x: x_values
y: y_values
z: [][]f64{len: z_values.len, init: z_values}
Expand All @@ -30,7 +29,7 @@ fn main() {
}
)

plt.set_layout(title: '3D Scatter Plot with Easing')
plt.layout(title: '3D Scatter Plot with Easing')
plt.show()!
}

Expand Down
Loading