File: example3.rs

package info (click to toggle)
rust-gnuplot 0.0.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 532 kB
  • sloc: makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,003 bytes parent folder | download
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
// This file is released into Public Domain.
use crate::common::*;

use gnuplot::*;
use std::vec::Vec;

mod common;

fn example(c: Common)
{
	let w = 61;
	let h = 61;
	let mut z1 = Vec::with_capacity((w * h) as usize);
	for i in 0..h
	{
		for j in 0..w
		{
			let y = 8.0 * (i as f64) / h as f64 - 4.0;
			let x = 8.0 * (j as f64) / w as f64 - 4.0;
			z1.push(x.cos() * y.cos() / ((x * x + y * y).sqrt() + 1.0));
		}
	}

	let mut fg = Figure::new();

	fg.axes3d()
		.set_title("Surface fg3.1", &[])
		.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
		.set_x_label("X", &[])
		.set_y_label("Y", &[])
		.set_z_label("Z", &[])
		.set_z_range(Fix(-1.0), Fix(1.0))
		.set_z_ticks(Some((Fix(1.0), 1)), &[Mirror(false)], &[])
		.set_view(45.0, 45.0);

	c.show(&mut fg, "example3_1");

	let mut fg = Figure::new();

	fg.axes3d()
		.set_title("Map fg3.2", &[])
		.surface(z1.iter(), w, h, None, &[])
		.set_x_label("X", &[])
		.set_y_label("Y", &[])
		.set_view_map();

	c.show(&mut fg, "example3_2");

	let mut fg = Figure::new();

	fg.axes3d()
		.set_pos_grid(2, 2, 0)
		.set_title("Base fg3.3", &[])
		.show_contours(true, false, Cubic(10), Fix(""), Auto)
		.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
		.set_view(45.0, 45.0);

	fg.axes3d()
		.set_pos_grid(2, 2, 1)
		.set_title("Surface", &[])
		.show_contours(false, true, Linear, Fix(""), Auto)
		.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
		.set_view(45.0, 45.0);

	fg.axes3d()
		.set_pos_grid(2, 2, 2)
		.set_title("Both + Fix Levels", &[])
		.show_contours(true, true, Linear, Fix("%f"), Fix(1))
		.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
		.set_view(45.0, 45.0);

	fg.axes3d()
		.set_pos_grid(2, 2, 3)
		.set_title("Custom Levels", &[])
		.show_contours_custom(true, false, Linear, Fix(""), Some(0f32).iter())
		.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
		.set_view(45.0, 45.0);

	c.show(&mut fg, "example3_3");
}

fn main()
{
	Common::new().map(|c| example(c));
}