Published using Google Docs
Scilab_plot
Updated automatically every 5 minutes

|| Home || FAQ || Research || Blogs || downloads || Images || Links || Random ||

Scilab Graphics


Table of Contents


Smallest things

clear a graphic window use

  • xbasc()
    clf()


If you have more than one graphic window, you can use the corresponding handle with above commands.

creating/closing a graphic window

  • f1=scf(0); // create new window
    f2=scf(1);

    delete(f1); //close window 0
    delete(f2); //close window 1

    or
    xdel([0,1]); //close both windows


-- 08 Nov 2005

In order to close all windows, there is a function called 'mtlb_close' which emulates Matlab's close function.

       

        mtlb_close all;

Or you can use the following command:

a = winsid();

xdel(a);

Changing graphic properties

Let f1 be the handle to the figure created using scf. Its children would be "Axes" as shown below.

-->set("current_figure",f1);
-->f1
 f1  =

Handle of type "Figure" with properties:
========================================
children: ["Axes";"Axes"]
figure_style = "new"
figure_position = [215,123]
figure_size = [610,461]
axes_size = [596,397]
auto_resize = "on"
figure_name = "Scilab Graphic (%d)"
figure_id = 1
color_map= matrix 37x3
pixmap = "off"
pixel_drawing_mode = "copy"
immediate_drawing = "on"
background =  -2
visible = "on"
rotation_style = "unary"
user_data = []



-->f1.children
 ans  =

2 by 1 matrix of handles:
=========================
Axes
Axes

-->f1.children(1)
 ans  =

Handle of type "Axes" with properties:
======================================
parent: Figure
children: "Compound"

visible = "on"
axes_visible = ["off","off","off"]
axes_reverse = ["off","off","off"]
grid = [-1,-1]
x_location = "bottom"
y_location = "left"
title: "Label"
x_label: "Label"
y_label: "Label"
z_label: "Label"
auto_ticks = ["on","on","on"]
x_ticks.locations = matrix 11x1
y_ticks.locations = matrix 11x1
z_ticks.locations = [-1;0;1]
x_ticks.labels = matrix 11x1
y_ticks.labels = matrix 11x1
z_ticks.labels = ["-1";"0";"1"]
box = "off"
sub_ticks = [1,1]
font_style = 6
font_size = 1
 more ?
font_color = -1

isoview = "off"
cube_scaling = "off"
view = "2d"
rotation_angles = [0,270]
log_flags = "nnn"
tight_limits = "off"
data_bounds = [0,0;0.001,0.001]
zoom_box = []
margins = [0,0,0,0]
axes_bounds = [0,0,0.001,0.001]

auto_clear = "off"
auto_scale = "on"

hiddencolor = 4
line_mode = "on"
line_style = 0
thickness = 1
mark_mode = "off"
mark_style = 0
mark_size_unit = "tabulated"
mark_size = 0
mark_foreground = -1
mark_background = -2
foreground = -1
 more ?
background = -2
clip_state = "off"
clip_box = []
user_data = []

-->f1.children(1).children
 ans  =

Handle of type "Compound" with properties:
==========================================
parent: Axes
children: matrix 13x1
visible = "on"
user_data = []

Note that f1.children(1) does not contain the polyline curves which we want to modify and hence we should look into children(2) now.

-->f1.children(2).children
 ans  =

Handle of type "Compound" with properties:
==========================================
parent: Axes
children: ["Polyline";"Polyline";"Polyline";"Polyline";"Polyline";"Polyline"]
visible = "on"
user_data = []

This figure has 6 polyline curves as shown above. Available properties for each polyline can be seen by executing following line:

-->f1.children(2).children.children(1)
 ans  =

Handle of type "Polyline" with properties:
==========================================
parent: Compound
children: []
visible = "on"
data = matrix 5001x2
closed = "off"
line_mode = "on"
fill_mode = "off"
line_style = 1
thickness = 1
arrow_size_factor = 1
polyline_style = 1
foreground = 36
background = -2
interp_color_vector = []
interp_color_mode = "off"
mark_mode = "off"
mark_style = 0
mark_size_unit = "point"
mark_size = 0
mark_foreground = -1
mark_background = -2
x_shift = []
y_shift = []
z_shift = []
 more ?
bar_width = 0
clip_state = "clipgrf"
clip_box = []
user_data = []

In order to increase the thickness of curves, we need to execute following commands:

-->f1.children(2).children.children(1).thickness=2;
-->f1.children(2).children.children(2).thickness=2;
-->f1.children(2).children.children(3).thickness=2;
-->f1.children(2).children.children(4).thickness=2;
-->f1.children(2).children.children(5).thickness=2;
-->f1.children(2).children.children(6).thickness=2;

 -- Date: 07 May 2008 Wednesday

[toc]


Two dimensional plot

plot() command

Good news is that scilab 3.1.1 comes with very good graphics editor and thus you can customize your plots using menus for adding labels, changing color etc. No need to remember clumsy commands to customize plots. Apart from this, it provides a more user friendly 'plot' command. A simple demonstration is given below:

t=0:0.01:1;

plot(t,sin(2*%pi*t),'r-.','thickness',3);

xgrid(color('gray'));

xtitle('Sine Curve','time','magnitude');

The third argument in plot command consists of two paramters namely color given by the letter 'r' and linestyle '-.'; fourth and fifth parameter are global properties specified in pairs {'thickness', 3}. A number of global properties may be added simultaneously. refer to online help for details. The labels can directly be provided inside the plot command as follows:

plot(x, y, ‘x axis label’, ‘y axis label’, ‘title of plot’)

[TOC]


plot2d command

Here I am plotting a simple 2-dimensional plot using plot2d command. I won't describe commands too much. I would rather give simple examples so that you can directly get started. FOr details refer to scilab online help.

t=0:0.01:1;

y=sin(2*%pi*t);

plot2d(t,y,style=[2],rect=[xmin,ymin,xmax,ymax]);

where 2 in style refers to color. you can get the color id by using command "color". see online help. 'rect' gives the axes boundaries. Just to get a default boundary remove 'rect' from above statement. in style option negative values like '-2' gives points rather than continuous line. For example, '-2' gives '+' symbol. getcolor() command opens up a menu where the color number can directly be selected.

To get grid give following command

xgrid(color('lightgray')); // you can also give number like xgrid(34)

A scilab plot consists of various 'graphic_entities'. In order to customise each one of them, one needs to get a handle to each one of them. We will see how we can customize each one of these entities.

if 'y' is a matrix, then plot2d plots each column of 'y' against 't'. So, make sure that size of each column of 'y' is same as that of 't'.

t=0:0.01:1;

y=[sin(t);cos(t)];  // size(y)=2x101

plot2d(t,y',style=[2,5]);

xgrid(color('gray'));

legends(['sin(t)';'cos(t)'],[2,5],opt="ur"); //opt="ur/lr/ul/ll/?"

legends command applies caption to each curve. The 'opt' is used to specify the location of legend box. location can also be specified through its actual coordinates. for instance opt=[x,y], places the legend at coordinate (x,y) . opt="?" is for interactive placement of legend using mouse (which is the default)

Some more examples for plot2d:

x = (0:0.01:1)';             // column vector

y1 = sin(x);                     // column vector

y2 = cos(x);                //column vector

plot2d([x, x], [y1, y2], [2, 3], '121', 'sin@cos');

Third argument gives the line color (2 - blue, 3 - green). Its a 1xP vector with as many entries as the number of columns in first two arguments. Legends are specified by two additional arguments given by 4th and 5th argument. The fourth argument is a 3-character string of digits with following meaning:

To keep the defaults for axes and display a legend , use '121' instead of '021' and specify an additional string parameter where each curve' description is separated by '@'. There is an alternative method which requires mulitple call to plot2d, but easier to handle. When only one curve is plotted, the third argument is 1x2 vector describing the line style and the legend position as shown below:

plot2d(x, y1, [2, 1], ‘121’, ‘sin’); // Legend position 1

plot2d(x, y2, [3, 2], ‘121’, ‘cos’); // Legend position 2

plot2d(x, y3, [6, 3], ‘121’, ‘tan’); // Legend position 3

xset()

The xset() function can control various attributes of a plot. Type xset() for an interactive

dialog. With this function you can control the fonts and font sizes of labels and numbers, fore-

ground and background colors, the sizes of the various marks used, the format for the display of

axis values, and lots more (type ‘help xset’). Try this:

        xset(‘background’, 1);                //  Black background

        xset(‘foreground’, 8);                //  White axes and labels

        xset(‘font’, 3, 10);                  //  Italics and bigger font size

        xset(‘thickness’,2);                  //  Thicker lines

        plot2d(0:10, 0:10, 2);                //  Blue line

A very good tutorial on plot2d command is available on internet. I found it through google. The original author may be found at this link and local copy of this document is available here.

-- 03 Aug 2007 Thursday

[TOC]


Axes Properties

This is how we customize various axis parameters.

a=gca();                       //get handle to "current_axes"

a.title.foreground=12;         //title text color

a.title.text="Sine Curve";

a.title.font_size=4;

a.x_label.text="Time (sec)";

a.x_label.font_size=2;

a.x_label.foreground=2; // xlabel text color

a.x_label.text="Magnitude";

a.x_label.font_size=2;

a.x_label.foreground=2; // ylabel text color

a.grid=[34,34]; // you can also set the grids here if don't use xgrid command.

There are many other axes properties which can be changed. Please refer to scilab online help.

Curve or polyline properties

p=get("hdl") //get handle to various entities

It gives output something like this:

p  =

 

Handle of type "Agregation" with properties:

============================================

parent: Axes

children: "Polyline"

visible = "on"

This is how we change the curve properties. For exhaustive list refer scilab online help.

p.children.line_style=0 ;       //continuous line ; possible values=0-9

p.children.thickness=3;                  // positive integer

p.children.polyline_style=1;  //possible values=1-5

p.children.foreground=color('blue'); // not required if you have already included 'style' in plot2d command.


Selecting a graphic window

If you want to plot different graphs on different windows, then you can select (or create) a graphic window by using following command:

-->xset("window",1)

use this command before plot command to select a window where you want to plot. For example,

-->xset("window",0)

-->plot2d(t,sin(t));

-->xset("window",1); //create window 1

-->plot2d(t,cos(t));

-->xset("window",0); //now select graphic window 0

-->clf;//clear the window 0

-->plot2d(t,sin(t)*sin(t)); //plot into window 0

"xset" many other useful features. Please go through the online help. Version 4.x would be the last series to support 'xset'. 


3D Plot

Three-dimensional plot

Following command plots a curve for a matrix x with 3 columns. xd is a 3-dimensional point.

param3d(x(:,1),x(:,2),x(:,3));

xlabel("x");

ylabel("y");

zlabel("z");   

param3d(xd(1),xd(2),xd(3));

a=get("current_axes");

h=a.children;

h(2).thickness=2;

h(2).foreground=2; //blue color

h(1).mark_mode="on"; //this is for point

h(1).mark_style=9; // circle

h(1).mark_foreground=5;  // red

[TOC]


|| Home || FAQ || Research || Blogs || downloads || Images || Links || Random ||