gnuplot

This is a simple gnuplot controller. The term controller in this context means that this code spawns a gnuplot process and controls it via pipes. Two syntaxes are supported by this code:
1
(new CGNUPlot()).Title("Test Plot").XRange([-1, 1]).YRange([-1, 1]).PlotRaw("x*x*x");

Or this syntax:

1
2
3
4
5
6
7
8
auto plot = new CGNUPlot();
with(plot)
{
    Title = "Test Plot";
    XRange = [-1, 1];
    YRange = [-1, 1];
    PlotRaw("x*x*x");
}
class C3DPlot : CGNUPlot
A 3D data plotter.
this(const(char)[] echo_filename = null)

See Also:

C3DPlot ZLabel(const(char)[] label) [@property]
Set the label for the Z axis.

Parameters:

labelLabel text.

Returns:

Reference to this instance.
C3DPlot ZRange(double[] range) [@property]
Set the range of the Z axis.

Parameters:

rangeAn array of two doubles specifying the minimum and the maximum. Pass null to make the axis auto-scale.

Returns:

Reference to this instance.
C3DPlot CRange(double[] range) [@property]
Set the range of the colobar.

Parameters:

rangeAn array of two doubles specifying the minimum and the maximum. Pass null to make the axis auto-scale.

Returns:

Reference to this instance.
CGNUPlot ZLogScale(bool use_log = true, int base = 10)
Enable logarithmic scale for the Z axis. Keep in mind that the minimum and maximum ranges need to be positive for this to work.

Parameters:

use_logWhether or not to actually set the logarithmic scale.
baseBase used for the logarithmic scale.

Returns:

Reference to this instance.
C3DPlot View(double[] x_z_rot) [@property]
Set the view direction.

Parameters:

x_z_rotRotation around the x and the z axes, in degrees. Pass null to set the "map" view, suitable for image plots.

Returns:

Reference to this instance.
C3DPlot Palette(const(char)[] pal)
Set the palette. This can be either "color" or "gray".

Parameters:

palName of the palette.

Returns:

Reference to this instance.
C3DPlot Palette(int[3] triplet...)
Set the palette using the RGB formulae. The default is 7, 5, 15. See the gnuplot documentation or the internet for more options.

Parameters:

tripletFormula indexes.

Returns:

Reference to this instance.
C3DPlot Palette(double[4][] colormap...)
Set the palette by specifying colors directly. Expects an array of quads of doubles ranging from 0 to 1. The first entry specifies the gray level to map to a color. The last three entries specify the color using r, g and b components.

Parameters:

colormapQuads of doubles.

Returns:

Reference to this instance.
C3DPlot Palette(scope bool delegate(out double gray, out double r, out double g, out double b) colormap)
Set the palette by specifying colors directly. Expects a delegate that fills out the passed quad of doubles ranging from 0 to 1. The first entry specifies the gray level to map to a color, and must increase at least every two iterations. The last three entries specify the color using r, g and b components. Iterations continues until the delegate returns false.

Parameters:

colormapColormap specifying delegate.

Returns:

Reference to this instance.
C3DPlot Plot(Data_t)(Data_t data, size_t w, size_t h, double[2] true_xrange = [0,0], double[2] true_yrange = [0,0], const(char)[] label = "")
Plot a rectangular matrix of values.

Parameters:

dataLinear array to the data or a numerical constant. Assumes row-major storage.
wWidth of the array.
hHeight of the array.
true_xrangethe x range that the columns of the matrix cover.
true_yrangethe y range that the rows of the matrix cover.
labelLabel text to use for this surface.

Returns:

Reference to this instance.
class C2DPlot : CGNUPlot
A 2D data plotter.
this(const(char)[] echo_filename = null)

See Also:

C2DPlot Histogram(Data_t)(Data_t data, size_t num_bins = 10, const(char)[] label = "")
Plot a histogram of some data. You probably want to set Style to "boxes" for this to look nice.

Parameters:

dataArray of data.
num_binsNumber of bins to use (by default it is 10)
labelLabel text to use for this histogram.

Returns:

Reference to this instance.
C2DPlot PlotLinearX(Y_t)(Y_t Y, double[2] x_range = [0, 0], const(char)[] label = "")
Plot an array vs a linear abscissa.

Parameters:

YArray of Y coordinate data or a numerical constant.
x_rangeRange of X values to assign to each value of Y. If the range is empty, the index of the value is used.
labelLabel text to use for this curve.

Returns:

Reference to this instance.
C2DPlot Plot(X_t, Y_t)(X_t X, Y_t Y, const(char)[] label = "")
Plot a pair of arrays. Arrays must have the same size.

Parameters:

XArray of X coordinate data or a numerical constant.
YArray of Y coordinate data or a numerical constant.
labelLabel text to use for this curve.

Returns:

Reference to this instance.
class CGNUPlot
Base class for all plot types.
This class is not terribly useful on its own, although you can use it as a direct interface to gnuplot. It also contains functions that are relevant to all plot types.
alias opCall Command

See Also:

this(const(char)[] echo_filename = null)
Create a new plot instance using the default terminal.

Parameters:

echo_filenameFilename to echo the commands to. If it is not null, then no other output will be produced.
CGNUPlot opCall(const(char)[] command)
Send a command directly to gnuplot.

Parameters:

commandCommand to send to gnuplot.

Returns:

Reference to this instance.
const(char)[] GetErrors(int timeout = 100)
Returns errors, if any, that gnuplot returned. This uses a somewhat hacky method, requiring a timeout value. The default one should suffice. If you think your errors are getting cut off, try increasing it. Only works on Linux.

Parameters:

timeoutNumber of milliseconds to wait for gnuplot to respond.

Returns:

A string containing the errors.
CGNUPlot PlotRaw(const(char)[] args, const(char)[] data = null)
Plots a string expression, with some data after it. This method is used by all other plot classes to do their plotting, by passing appropriate argumets. Can be useful if you want to plot a function and not data:
1
plot.PlotRaw("x*x");

Parameters:

argsArguments to the current plot command.
dataData for the current plot command. This controller uses the inline data entry, so the format needs to be what that method expects.

Returns:

Reference to this instance.
CGNUPlot Flush()
If plotting is held, this plots the commands that were issued earlier. It does not disable the hold.

Returns:

Reference to this instance.
CGNUPlot Hold(bool hold) [@property]
Activates plot holding. While plotting is held, successive plot commands will be drawn on the same axes. Disable holding or call Flush to plot the commands.

Parameters:

holdSpecifies whether to start or end holding.

Returns:

Reference to this instance.
void Quit()
Quits the gnuplot process. Call this command when you are done with the plot.
CGNUPlot Refresh()
Refreshes the plot. Usually you don't need to call this command.

Returns:

Reference to this instance.
CGNUPlot XLabel(const(char)[] label) [@property]
Set the label for the X axis.

Parameters:

labelLabel text.

Returns:

Reference to this instance.
CGNUPlot YLabel(const(char)[] label) [@property]
Set the label for the Y axis.

Parameters:

labelLabel text.

Returns:

Reference to this instance.
CGNUPlot XRange(double[] range) [@property]
Set the range of the X axis.

Parameters:

rangeAn array of two doubles specifying the minimum and the maximum. Pass null to make the axis auto-scale.

Returns:

Reference to this instance.
CGNUPlot YRange(double[] range) [@property]
Set the range of the Y axis.

Parameters:

rangeAn array of two doubles specifying the minimum and the maximum. Pass null to make the axis auto-scale.

Returns:

Reference to this instance.
CGNUPlot XLogScale(bool use_log = true, int base = 10)
Enable logarithmic scale for the X axis. Keep in mind that the minimum and maximum ranges need to be positive for this to work.

Parameters:

use_logWhether or not to actually set the logarithmic scale.
baseBase used for the logarithmic scale.

Returns:

Reference to this instance.
CGNUPlot YLogScale(bool use_log = true, int base = 10)
Enable logarithmic scale for the Y axis. Keep in mind that the minimum and maximum ranges need to be positive for this to work.

Parameters:

use_logWhether or not to actually set the logarithmic scale.
baseBase used for the logarithmic scale.

Returns:

Reference to this instance.
CGNUPlot Title(const(char)[] title) [@property]
Set the title of this plot.

Parameters:

titleTitle text.

Returns:

Reference to this instance.
CGNUPlot Style(const(char)[] style) [@property]
Set the style of this plot. Any style used by gnuplot is accetable here.

Here are some commonly used plot styles.

For 2D and 3D plots.

    lines
    points
    linespoints

For 3D plots only:

    image - Image plotting
    pm3d - Surface plotting

Parameters:

titleTitle text.

Returns:

Reference to this instance.
CGNUPlot PointType(int type) [@property]
Set the point type to use if plotting points. This differs from terminal to terminal, so experiment to find something good.

Parameters:

typePoint type. Pass -1 to reset to the default point type.

Returns:

Reference to this instance.
CGNUPlot Thickness(float thickness) [@property]
Set the thickness of points/lines for subsequent plot commands.

Parameters:

thicknessThickness of the point/lines.

Returns:

Reference to this instance.
CGNUPlot Color(int[3] color...)
Set the color of points/lines for subsequent plot commands.

Parameters:

colorTriplet of values specifying the red, green and blue components of the color. Each component ranges between 0 and 255.

Returns:

Reference to this instance.
CGNUPlot Color()
Set the color of points/lines for subsequent plot commands.

Parameters:

colorTriplet of values specifying the red, green and blue components of the color. Each component ranges between 0 and 255.

Returns:

Reference to this instance.
CGNUPlot AspectRatio(double ratio) [@property]
Set the aspect ratio of the plot. Only works with 2D plots (or image 3D plots).

Parameters:

ratioAspect ratio to use (height / width).

Returns:

Reference to this instance.
CGNUPlot OutputFile(const(char)[] filename) [@property]
If you set a terminal that can output files, use this function to set the filename of the resultant file.

Parameters:

filenameFilename text.

Returns:

Reference to this instance.
CGNUPlot Terminal(const(char)[] term) [@property]
Sets a terminal type, allowing, for example, output to a file.

Parameters:

termTerminal name. Notable options include: wxt, svg, png, pdfcairo, postscript.