logo for matrixlab-examples.com
leftimage for matrixlab-examples.com


Scilab 2D plots

This is a brief introduction to the great potential of Scilab’s graphic capabilities. We’ll review a few of the basic commands and operations to carry out this important task in sofisticated software like Scilab or Scicoslab.
 


Simple Graphic Representation

In a simple graphic representation we just need two vectors with the same number of elements. The idea is to show a mathematical relationship or function that results in a 2D graph. The built-in functions that allow us to do that are plot and plot2d.

The following functions are quite compatible with Matlab:

  • plot
  • subplot
  • xlabel
  • ylabel
  • legend
  • title 

These functions are different from the Matlab ones:

  • xdel(n) – deletes a figure window
  • scf(n) – opens a figure window
  • xgrid – shows a grid on the plot
  • ax = get("current_axes"); ax.data_bounds = [xL, yL; xU, yU]; - it’s an approximation of the Matlab axis function


This code  

x = -10 : .1 : 10;  // define our independent values
y = cos(x) .* x;    // define our dependent values
plot(x, y)          // plot both vectors    

xlabel('x'); ylabel('y');         // define labels
legend('y = cos(x) * x');         // define legend
title('My First Scilab 2D Plot')  // add title

 
produces this Scilab plot

Scilab 2D plots - basic functions

  

We can re-define the axis values and add a grid by adding these lines to the previous code:

// get the handle of the newly created axes
ax = get("current_axes");

// clip axes
ax.data_bounds = [-10, -6; 10, 8];

// add grid
xgrid                    

 
The resulting plot is   

Scilab grid and bounded axes

 
To erase the contents of one figure window, you only need to type the command clf in the command line, or you can select Erase Figure in the edit menu of the figure selected.

If you want to generate new plots without removing the previous one, it’s necessary to indicate the creation of a new one using the command ‘scf’, whose syntax is scf(integer number of the new plot).

If you run the code below 

x = -10 : .1 : 10;  // define our independent values
y = cos(x) .* x;    // define our dependent values
y2 = 3 * sin(x);    // define another function
plot(x, y,'b', x, y2, 'r')           

xlabel('x'); ylabel('y');     // define labels
legend('y = cos(x) * x', 'y2 = 3 sin(x)'); // define legend 

you can see two lines in the same window, each with a different legend and color

 
Scilab - two functions in one window


 From 'Scilab 2D Plots' to Matlab home

 From 'Scilab 2D Plots' to Scilab
 

Top


footer for matlab page