Plot functions of SCILAB: plot Functions
The most basic is the plot function, which is similar to the plot function in MATLAB.
xdata = linspace(1,10,50);ydata = sin(xdata);plot(xdata, ydata);
For function plotting, you do not need to calculate the ydata in advance. For example, the results drawn in the following example are the same.
plot (xdata, sin);
This also saves some memory usage.
If you only set the general title, you can do this:
title("My Plot");
If you want to set the title of the XY axis, you can do this:
xtitle("This is a Plot", "x axis", "y axis");
The color and line type can be controlled by adding the third parameter to the plot. The legend () function can set labels. For example:
plot(xdata, sin, "o-r");plot(xdata, cos, "*--y");legend("sin", "cos");
Save image
After drawing a picture, you certainly want to save it to a file. SCILAB supports many image formats. Each of the following functions corresponds to an image format.
Xs2png |
Xs2fig |
Xs2pdf |
Xs2gif |
Xs2svg |
Xs2jpg |
Xs2ps |
Xs2bmp |
Xs2emf |
XSS 2ppm |
If we want to save the image of window 0 as PNG, we can execute the following statement.
xs2png(0, "pic.png");
As mentioned above, the number is written in the drawing window. SCILAB can display multiple image windows at the same time, and identify which drawing window is operated by the window number.
Most of the time we want to be able to add a grid to the image, this operation is easy to implement in MATLAB:
Grid on enable Grid
Grid off
SCILAB does not have such a statement, but it can be replaced by the following statement.
Enable grid:
set(gca(),"grid",[1 1]);
Close the grid:
set(gca(),"auto_clear",[-1 -1]);
The following figure shows the effect after the grid is Enabled:
Set the word size for the scale on the axis:
xset("font size", 4);
Sadly, the font size of the title is invalid... There is no solution yet.
Set the background color of the image:
xset("background", color);
Here, color is an integer indicating the index in colormap. You can use the getcolor () function to obtain the current colormap.
getcolor();
Set the background color to green
xset("background", 3);
(To be continued)