Prev: plotting-data.html Up Next: layers.html
Plotting functions

Practical Guide:

plot(_1,sin(_1)+_1);                     // plots the function sin(x) + x
plot(_1,_2,exp(-_1*_1 - _2*_2)).ds(cboxes()) // plots a gauss, 2 dim (see the examples !!)

Graphs are automatically deleted!!!

In the following paragraphs many plot commands will be described, which plot data from arrays, files, output of commands, etc. All of these have the common property, that they set the autodel flag of the resulting graph to true. Therefore, whenever the frame containing this graph is cleared, this graph will be deleted, any pointer to this will be invalid!

How to plot functions?
Plotting functions in BLOP is similar to the parametric mode of gnuplot. To plot functions, call the plot(...) and mplot(...) commands with only functions as arguments. In this case 1 (or 2) parameters will be swept in a given range, and the provided functions (arguments of the plot(...) and mplot(...) commands) will be evaluated at discrete values of these parameters. The first parameter will be the first argument, the second parameter (if used) will be the second argument of these functions. That is, _1 and _2 can be used in the function definitions to refer to these parameters, but higher ones (such as _3) should NOT be used, because these functions will never be called with more than 3 arguments.

The resulting values will be stored in the graph (the first function's values in the first column, etc). From this point on everything is the same as for data-plotting: the drawing style of the graph will decide, how to interpret the data in the columns.

This means, that whenever you want to plot a 'simple function', like sin(x), you should not say plot(sin(x))!

Therefore every time you want to plot a 'simple function' (a single-valued function of the independent variable), write this:
plot(_1, sin(_1));

To plot a parameterized half-circle, for example, write this:

The number of parameters to be swept (1 or 2) is deduced from the to-be-plotted functions: if any of them uses 2 arguments, 2 parameters will be scanned, otherwise only 1.

Plotting functions with condition
To plot functions in a domain, where any combination of the parameters satisfy some condition, use the following two functions:
plot_if(const function &condition,
        const function &f1,
	const function &f2=unset,
	const function &f3=unset,
	const function &f4=unset);
(or the similar mplot_if(...) function). The function 'condition' is evaluated on the same arguments, with which also f1...f4 will be called. If it returns non-0 value, the point is taken. Example:
function x = _1;
function y = _2;
function gaus = exp(-x*x-y*y);
plot_if(x*x+y*y<1, x, y, gaus).ds(cboxes()).p1range(-1,1).p2range(-1,1);
This piece of code plots a 2D gaussian within the unit circle. If you would want to make a cut in the z-value (i.e. the gaussian), use that:

Specifying parameter range(s)
The object returned from a plot(...) or mplot(...) command is a fgraph (function graph). To specify the range of the parameter(s) of it, call the p1range(min,max) or p2range(min,max) member functions of an fgraph:
plot(_1, sin(_1)).p1range(0,20);
plot(_1, _2, exp(-_1*_1 - _2*_2)).p1range(-5,5).p2range(-5,5).ds(cboxes()); // 2 params, a 2D Gauss

By default, the parameters p1 (and p2, if needed) are scanned in a linear way to sample the function values. The p1log(bool) (p2log(bool)) member functions can set a flag to make the scan logarithmic, i.e. the corresponding parameter will be incremented by the same *factor* in each step.

Accessing the most recently plotted function

The get::lastf() function returns a pointer to the most recently plotted fgraph of the current frame (or 0, if no functions were plotted yet). This can be used to modify it, for example (interactively checking how a function behaves


Source files:

Prev: plotting-data.html Up Next: layers.html