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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
// This file is released into Public Domain.
use crate::common::*;
use gnuplot::*;
use std::iter::repeat;
mod common;
fn example(c: Common)
{
let x = &[1i32, 2, 3, 4, 5];
let x = x.iter2();
let y1: Vec<i32> = x.map(|&v| v * v).collect();
let y1 = y1.iter2();
let x2 = &[1i32, 4, 5];
let x2 = x2.iter2();
let y2: Vec<i32> = x2.map(|&v| v * v).collect();
let y2 = y2.iter2();
let w = repeat(0.5f32);
let x3 = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
let x3 = x3.iter2();
let y3: Vec<i32> = x3.map(|&v| v * v * v).collect();
let y3 = y3.iter2();
let zw = 16;
let zh = 16;
let mut z1 = Vec::with_capacity((zw * zh) as usize);
for i in 0..zh
{
for j in 0..zw
{
let y = 8.0 * (i as f64) / zh as f64 - 4.0;
let x = 8.0 * (j as f64) / zw as f64 - 4.0;
z1.push(x + y);
}
}
let mut fg = Figure::new();
fg.axes2d()
.set_title("Arrows fg2.1", &[])
.lines(x, y1, &[LineWidth(3.0), Color("brown"), LineStyle(DotDash)])
.arrow(
Graph(0.5),
Graph(1.0),
Axis(1.0),
Axis(1.0),
&[
ArrowType(Filled),
ArrowSize(0.1),
LineStyle(DotDotDash),
LineWidth(2.0),
Color("red"),
],
)
.arrow(
Graph(0.5),
Graph(1.0),
Axis(3.0),
Axis(9.0),
&[ArrowType(Open), Color("green")],
);
c.show(&mut fg, "example2_1");
let mut fg = Figure::new();
fg.axes2d()
.set_title("Boxes fg2.2", &[])
.boxes(
x2,
y2,
&[
LineWidth(2.0),
Color("cyan"),
BorderColor("blue"),
LineStyle(DotDash),
],
)
.boxes_set_width(
x,
y1,
w,
&[LineWidth(2.0), Color("gray"), BorderColor("black")],
);
c.show(&mut fg, "example2_2");
let mut fg = Figure::new();
fg.axes2d()
.set_title("Axis Ticks fg2.3", &[])
.lines(x3, y3, &[LineWidth(2.0), Color("blue")])
.set_x_ticks_custom(
x3.map(|&x| Major(x as f32, Fix("%.2f ms".to_string())))
.chain(x3.map(|&i| i as f32 + 0.5).map(|x| Minor(x))),
&[MajorScale(2.0), MinorScale(0.5), OnAxis(true)],
&[TextColor("blue"), TextAlign(AlignCenter)],
)
.set_x_log(Some(10.0))
.set_y_ticks(
Some((Fix(100.0), 1)),
&[Mirror(false), Format("%.1f s")],
&[],
);
c.show(&mut fg, "example2_3");
let mut fg = Figure::new();
fg.axes2d()
.set_title("Border, Axes fg2.4", &[])
.set_border(true, &[Left, Bottom], &[LineWidth(2.0)])
.set_x_ticks(Some((Fix(1.0), 1)), &[Mirror(false)], &[])
.set_y_ticks(Some((Fix(50.0), 0)), &[Mirror(false)], &[])
.lines(x3, y3, &[LineWidth(2.0), Color("blue")])
.set_x_axis(true, &[LineWidth(2.0), LineStyle(DotDotDash)])
.set_y_axis(true, &[LineWidth(2.0), Color("red")]);
c.show(&mut fg, "example2_4");
let mut fg = Figure::new();
fg.axes2d().set_title("Image fg2.5", &[]).image(
z1.iter(),
zw,
zh,
Some((-4.0, -4.0, 4.0, 4.0)),
&[],
);
c.show(&mut fg, "example2_5");
let mut fg = Figure::new();
fg.axes2d()
.set_title("Image without borders fg2.6", &[])
.set_border(false, &[], &[])
.set_x_ticks(None, &[], &[])
.set_y_ticks(None, &[], &[])
.image(z1.iter(), zw, zh, Some((-4.0, -4.0, 4.0, 4.0)), &[]);
c.show(&mut fg, "example2_6");
let x4 = &[1f32, 10.0, 100.0];
let y4 = &[1f32, 3f32, 9f32];
let mut fg = Figure::new();
fg.axes2d()
.set_title("Logarithmic fg2.7", &[])
.lines(x4.iter(), y4.iter(), &[])
.set_x_ticks(Some((Auto, 1)), &[], &[])
.set_y_ticks(Some((Auto, 1)), &[], &[])
.set_x_log(Some(10.0))
.set_y_log(Some(3.0));
c.show(&mut fg, "example2_7");
let mut fg = Figure::new();
fg.axes2d()
.set_title("Axis Grid fg2.8", &[])
.lines(x3, y3, &[LineWidth(2.0), Color("blue")])
.set_y_ticks(Some((Auto, 2)), &[], &[])
.set_grid_options(true, &[LineStyle(DotDotDash), Color("black")])
.set_minor_grid_options(&[LineStyle(SmallDot), Color("red")])
.set_x_grid(true)
.set_y_grid(true)
.set_y_minor_grid(true);
c.show(&mut fg, "example2_8");
}
fn main()
{
Common::new().map(|c| example(c));
}
|