Awesome
vplot 1.0
vplot is a wrapper for GNU Plot (gnuplot_i). The source of gnuplot_i
I have downloaded from this link. Files listed on gnuplot_i are taken from downloaded sources, including the license file.
Dependecies
First, you need to install the gnuplot
.
Get started
Import vplot
library:
import vplot
Declare a new Plot object:
mut p1 := vplot.new()
Set a style and plot a slope of this function y=ax+b
, where a = 2
and b = 0
and title y=2x
. Also set label of X axis (x
) and for Y axis (2x
).
p1.style(vplot.style_linespoints)
p1.label_x(`x`)
p1.label_y(`y`)
p1.plot_slope(2.0)
Whenever you start a new plot session, you should closed it once you are done with it. But, in this simple example, you would not be able to see the output. To be able to see the output, we are going to call os.input()
function in order to wait for any key to be pressed before closeing the plot session.
os.input('Press any key ...')
p1.close()
Change log:
- Removed all examples and moved to vplot-playground
- Adding support for multiplots (similar to subplots in GNU Octave). Check example multiplot.v
Documentation
Function | Description |
---|---|
vplot.new_plot | Creates and returns new Plot object. |
vplot.Plot.close() | Closes the plot sessions and kills corresponding PID. |
vplot.Plot.command(command string) | Executes a GNU Plot command |
vplot.Plot.commands(commands []string) | Executes an array od GNU Plot commands |
vplot.Plot.style(style string) | Sets the plot style. Check Plot styles. |
vplot.Plot.label_x(label string) | Sets the label of X axis. |
vplot.Plot.label_y(label string) | Sets the label of Y axis. |
vplot.Plot.reset() | New plot erases the previous plot(s). |
vplot.Plot.plot(d[]f64, string)? | Plots an array of f64 data. It returns an error if the input array is empty. The second argument is the title of this plot. |
vplot.Plot.plot2(x []f64, y []f64, title string) | Plots a pair of data from two arrays of []f64 data type. It returns an error if there is mismatch on length between two input arrays, or one of them is an empty array. The second argument is the title of this plot. |
vplot.Plot.plot_slope(a f64, b f64, title string) | Plots a slop function y = a*x + b , where a and b , are the first and second argument. The third argument is the title of this function. |
vplot.Plot.plot_equation(equation string, title string) | As per gnuplot_i documentations, this plots out a curve of given equation. The general form of the equation is y=f(x), you only provide the f(x) side of the equation. |
vplot.write_x_csv(filename string, d []f64, title string) | Writes a CSV file of a given array of f64 . It return true/false if it failed or not to write the CSV file, otherwise, it returns an error if the given array is empty. |
Plot styles
vplot.style_lines
vplot.style_points
vplot.style_linespoints
vplot.style_impulses
vplot.style_dots
vplot.style_steps
vplot.style_errorbars
vplot.style_boxes
vplot.style_boxeserrorbars
Tested functions
-
new
-
Plot.close()
-
Plot.style(string)
-
Plot.plot_slope(f64, f64, string)
-
Plot.plot_equation(string, string)
-
Plot.reset()
-
Plot.enable_multiplot(Multiplotter)
-
Plot.disable_multiplot()
-
Plot.command(string)
-
Plot.commands([]string)
-
Plot.plot2d([]f64, []f64, string)
-
Plot.plot([]f64, string)
-
Plot.label_x(string)
-
Plot.label_y(string)
-
vplot.write_x_csv(string, []f64, string)
-
vplot.write_xy_csv(string, []f64, []f64, string)
-
vplot.write_csv(string, []f64, []f64, string)
-
vplot.PlotSession{}
-
vplot.plotter(PlotSession)