[scilab-Users] Plotting matrix

Antoine Monmayrant antoine.monmayrant at laas.fr
Fri Oct 15 14:27:33 CEST 2010


Le 15/10/2010 13:24, Mathieu Dubois a écrit :
> Hello,
>
> Thanks to Samuel I have a working function (see attachment). To plot 
> arbitrary values the function first scales them in [0,1] so very low 
> values are represented with small circles and colours from the bottom 
> of the colormap and high values with circles of diameter close to 1 
> (and colours from the top of the colormap). The parameter threshold is 
> used to represent very low values (in the current version this 
> introduces a slight bias).
>
> The function works reasonably well but to be complete:
>  - the parameter threshold (which specify what to do with very low 
> values) should be optional
>  - the user should be able to give the scaling parameters (for 
> instance to represent sevral matrices with the same colorscale)
> I will find time to do that.
>
> The function is named Matplot2 because it's like Matplot and Matplot1. 
> It would be nice to include it into scilab... I can fill a request on 
> bugzilla...
>
> By the way I have seen that scilab supports named parameters but I 
> didn't find documentation/examples. My question:
>  - how can I use named parameters?
>  - can I set a default value for a named parameter?
> This would be a nice alternative to varargin...
>
> Mathieu
>
> On 10/15/2010 10:55 AM, Mathieu Dubois wrote:
>> On 10/15/2010 09:31 AM, Samuel GOUGEON wrote:
>>>  Hello Mathieu,
>>>
>>> ----- Message d'origine -----
>>> De : Mathieu Dubois
>>> Date : 14/10/2010 21:02:
>>>> Hello,
>>>>
>>>> I would like to represent data in a matrix by coloured small 
>>>> circles (for gnuplot users I want to reproduce something like the 
>>>> "with points" option).
>>>>
>>>>
>>>> The following script works but is rather slow. axis is a handle the 
>>>> axes and h a handle to the figure (it is hidden before the script 
>>>> and then reshowed to speed up the rendering).
>>>> The data are probabilities so the scaling is simple. The circles 
>>>> are approximated by 10 facets polygons which is not very beautiful. 
>>>> The probability gives the radius of the circle and its colour.
>>> Why not using
>>>
>>> drawlater
>>> //... loop (if really needed. Is it?)
>>> xfarcs(...)
>>> // ... end of loop
>>> drawnow
>>>
>>> ?
>>>
>>>
>> Thanks for your suggestion! I'm working on it (and it looks 
>> promising). I will sent it to the list...
For most of the optional parameters in my functions, I use "param_name", 
"param_value" pairs.

Here is an example of a function that color the surface between two curves:

//////////////////////////////////////////////////////////
// Plot area between two curves
function [h,epoly,ey1,ey2]=BetweenCurves(x,y1,y2,varargin)
//
//      Plots two curves and fill the area in between
//
//      INPUTS:
//              x       vector (1,n) of horizontal coordinates
//              y1      vector (1,n) value of 1st curve y1(x)
//              y2      vector (1,n) value of 2nd curve y2(x)
//       -- optional inputs: pairs "keyword","value" --
//              "handle",h      handle to the graphic window to use
//              "axis",a      handle to the graphic axis to use
//              "foreground", colorid   id of the color to use for 
painting the area
//              "background", colorid   id of the color to use for 
curves stroke
//
//      OUTPUTS:
//              h       handle to the graphic window used
//              epoly   handle to the polygone that fill the area in between
//              ey1     handle to first curve
//              ey2     handle to second curve

//default values for optional argument
       hfig=-1;
       background=%nan;
       foreground=%nan;
// scan varargin for optional parameter pairs (they can appear in any order)
    for i=1:2:length(varargin)
       keyword=varargin(i);
       value=varargin(i+1);
       select keyword
          case "handle" then
             hfig=value;
             scf(hfig);
          case "axis" then
             axis=value;
             sca(axis);
             hfig=axis.parent;
          case "background" then
             background=value;
          case "foreground" then
             background=value;
       end
    end
// special treatment for handle (aka hack alert)
    if typeof(hfig) ~= "handle" then
       hfig=scf();
    end
    h=hfig;
    scf(hfig);
    xfpoly([x,x($:-1:1)],[y1,y2($:-1:1)]);
    epoly=gce();
    plot(x,y1);
    ey1=gce();
    plot(x,y2);
    ey2=gce();
// background setting
    if (~isnan(background)) then
       // optional background specified
       epoly.background=background;
    else
       // default background
       epoly.background=color("gray87");
    end
// foreground setting (as for background)
    if (~isnan(foreground)) then
       epoly.foreground=foreground;
       ey1.children.foreground=foreground;
       ey2.children.foreground=foreground;
    else
       epoly.foreground=color("gray65");
       ey1.children.foreground=color("gray65");
       ey2.children.foreground=color("gray65");
    end
endfunction

/////////////////////////////////////////////////////////


It is not refined and errors in the optional parameters are not handled.
I don't even knows if it the right way to do that, but it suits my needs.

Hope it helps,

Antoine





More information about the users mailing list