Crates.io | gnuplot-wrapper |
lib.rs | gnuplot-wrapper |
version | 0.0.4 |
source | src |
created_at | 2024-10-19 13:07:00.417359 |
updated_at | 2024-10-26 19:31:05.749212 |
description | A small wrapper for working with gnuplot. |
homepage | |
repository | |
max_upload_size | |
id | 1415356 |
size | 18,566 |
Gnuplot - to get started with gnuplot.
GnuplotLiveProcess - for working with gnuplot in interactive mode.
GnuplorScriptProcess - for working with gnuplot in script launch mode.
Script - script for gnuplot.
Gnuplot::execute(script).wait().unwrap();
First of all we need to start gnuplot. There are three ways to do this.
Gnuplot::new(); // equals to Gnuplot::new_with_path_str("gnuplot")
Gnuplot::new_with_path_str("gnuplot");
Gnuplot::new_with_path(&String::from("gnuplot"));
Then you need to decide in which mode you want to work with gnuplot and create an instance of gnuplot.
Scripting mode:
let script: Script = ...;
let mut gnuplot_process: GnuplorScriptProcess = gnuplot.execute_script(script);
Live mode:
let mut gnuplot_process: GnuplotLiveProcess = gnuplot.run_live();
Wait for gnuplot to complete.
gnuplot_process.wait();
let mut script = Script::new();
script.add_raw_command("set term qt 0");
script.add_raw_command("plot sin(x)");
script.add_raw_command("set term qt 1");
script.add_raw_command("plot cos(x)");
script.save("/tmp/wk.plt");
gnuplot_process.write("set term qt 1");
gnuplot_process.write("pause mouse close");
gnuplot_process.wait();
You can use figure
let mut g: Gnuplot = Gnuplot::new();
let mut gp: GnuplotLiveProcess = g.run_live();
let mut fig = Figure::new(0, "/tmp/d.dat");
let data: Vec<f64> = vec![0.0, 0.2, 0.4, 0.3];
let time: Vec<f64> = vec![1.1, 2.1, 3.1, 4.1];
fig.plot(&data, &time);
let data: Vec<f64> = vec![1.0, 1.2, 1.4, 1.3];
let time: Vec<f64> = vec![1.0, 2.0, 3.0, 4.0];
fig.plot(&data, &time);
fig.title("Test figure");
gp.plot_figure(fig);
gp.wait();