The method plot2d() is used to plot functions and arrays in 2D. One can add title, labels, change the minimum and maximum ranges for X-axis and Y-axis. You can also apply different styles.
First, let us create a canvas and prepare for plotting of data.
There are several methods associated with it:
To draw a function, first create a function using a symbolic variable “x”, then create a canvas and then use draw2d(o) to plot the function.
You can set the X and Y ranges for the plotted functions. In this example we differentiate an analytic function and then plot in in the given range [0-10] in X and [-1-10] in Y:
Plotting of special functions is also possible; they all can accept not only a single value but vectors.
Here we plotted the error function. Other functions are described in functions.
One can draw multiple functions, setting a new color, style and name for the second function:
It should be noted that functions can also be plotted by parsing a string:
Let as show a simple example of plotting sin(x) between 0 and 10 with a step 0.1
You can draw the second plot with a different style:
You can plot data with errors. Errors are shown as lines, and can be attributed to Y-values (asymmetric upper and lower errors) and to X-values (left and right error). Errors can be asymmetric.
In this example, we plot data with symmetric errors on Y (which is 40% of the y-values). The array “z” represents symmetric errors on the Y-values.
In this example, we plot data with asymmetric errors on Y (which is 40% and 80% of the y-values). In this example, the upper error on Y is 40% of the value y, while lower error is 80% of the value y:
Now let us plot errors on X and Y. We assume that left error is 30% of X value, and right value is 60% of x value.
Finally, here is a custom example:
You can pass the following options to the “draw2d” method:
You can use the draw2d() method to display histograms. Read the section Histograms to learn how to create histograms.
There are several methods associated with it: clear2d (clear the canvas from data) and export2d(file), to export the plot to the vector format image, such as PDF, EPS, as well as PNG and JPG. When exporting images to the file, use the file extension to define image format. For example, export2d(“image.pdf”) indicates that the plot will be saved into the PDF format, export2d(“image.eps”) tells that the plot will be saved into the high-quality vector format using EPS/PS format.