[Scilab-users] 4-D plots.

Adrian Weeks aweeks at hidglobal.com
Fri Jan 25 11:01:17 CET 2019


Hello,

I want to plot a function of three independent variables ( v = f(x, y, z) ) so that I can visualize it.
Essentially, this requires a 4-D plot but I can do it by using param3d to give me three independent axes then representing the value of the function at each point by using the colour or size of the dot.
This all works nicely but the problem is the slowness of the plotting operation:

for i = 1: size(dots, 'r') do
                param3d(dots(i, 1), dots(i, 2), dots(i, 3));
                pl = gce();
                pl.line_mode = 'off';
                pl.mark_mode = 'on';
                pl.mark_size_unit = 'point';
                pl.mark_size = 10;                                                            // Using dot colour to display the dependent variable
                pl.mark_foreground = dots(i, 4);
//            pl.mark_size = dots(i, 4);                                               // Using dot size to display the dependent variable
//            pl.mark_foreground = size(cmap, 'r') - 1;
end

Is it possible to 'vectorize' this operation ?

At present the dot information is stored in a single matrix using columns for x, y, z & colour:  it needn't be done this way.
Notice the line_mode, mark_mode etc. switching - I haven't found a way to set these values as defaults.
Instead of plotting each dot I tried plotting a single, master dot, then copying its handle to all the other points.  The effect of this was that changing the colour of one changed the colour of them all.

The full test programme is given below.
I'm using Windows 7 and Scilab 5.4.1

Many thanks in anticipation,
Adrian.



//*******************************************************************************
// 3D plot trial.
//*******************************************************************************
// 1) The number of colours in the colour map sets the granularity of the displayed values.
// 2) A step size, in conjunction with the range of each of the three independent variables, sets
//     the total number of dots.
// 3) For all combinations of the independent variable values, calculate the dependent variable.
// 4) Optionally, remove all dependent variable values lying outside prescribed limits.
// 5) Convert all (remaining) dependent variable values to a colour number.
// 6) Plot all dots using the calculated colour map.
// 7) Dot size could be varied, as an alternative to dot colour.

xdel(winsid());
clear;
clearglobal;
resethistory;
clc;

//-------------------------------------------------------------------------------
// Graded-colour generator.
// xgrade is a continuous parameter, range 0 to 1, which varies the colour grade (brightness)
//  between limits pale & dark where pale = 255 would mean white and dark = 0 would mean black.
// Practical values are pale = 220, dark = 120.

function RGB = SetColour(pale, dark, colour, xgrade)
                k1 = pale + 255 - dark;
                k2 = round(xgrade * k1);
                if xgrade <= pale / k1 then
                                p = 255;
                                s = pale - k2;
                else
                                p = pale + 255 - k2;
                                s = 0;
                end
                select colour
                case #rd then
                                RGB = [p, s, s];
                case #yw then
                                RGB = [p, p, s];
                case #gn then
                                RGB = [s, p, s];
                case #cn then
                                RGB = [s, p, p];
                case #be then
                                RGB = [s, s, p];
                case #ma then
                                RGB = [p, s, p];
                else
                                RGB = [0, 0, 0];
                end
endfunction

#rd = 1
#yw = 2
#gn = 3
#cn = 4
#be = 5
#ma = 6
Ncolour = 6
Ngrade = 11
pale = 220
dark = 120

//-------------------------------------------------------------------------------
// Graded-colour colour-map generator.
// Colours are mapped consecutively in blocks of Ngrade RGB values.
// The RGB triplet for a particular colour and grade is accessed by calculating the row index using:
//   r = Ngrade(colour - 1) + grade.

function cmap = ColourMap(Ncolour, Ngrade)
                cmap = []
                for colour = 1: Ncolour do
                                for xgrade = linspace(0, 1, Ngrade) do
                                                RGB = SetColour(pale, dark, colour, xgrade) / 255;
                                                cmap = [cmap; RGB];
                                end
                end
                cmap = [cmap; [0, 0, 0]];                               // Add black & white
                cmap = [cmap; [1, 1, 1]]
endfunction

//-------------------------------------------------------------------------------
// An arbitrary example function, suitable for plotting, which generates values between 1 & 11
//  dependent on the three input variables.
// The output range 1..11 suits the colour-map range.

function v = F(x, y, z)
                v = round((x/10 + y/10 + (z - 5.5)^2/20.25 - 0.2)/0.28) + 1;
endfunction

//-------------------------------------------------------------------------------
// Generate the dots to be plotted.

colour = #rd
index = Ngrade * (colour - 1)
N = 10
values = linspace(1, 10, N)
dots = []
for x = values do
                for y = values do
                                for z = values do
                                                dots = [dots; x, y, z, F(x, y, z) + index];
                                end
                end
end

//-------------------------------------------------------------------------------
// Prepare a 3D plot with appropriate colour-map.

cmap = ColourMap(Ncolour, Ngrade);
fg = scf();
//fg.figure_position = [,];
//fg.figure_size = [,];
fg.color_map = cmap;
fg.background = size(cmap, 'r');
da = gda();
da.line_mode = 'off';
da.mark_mode = 'on';
da.mark_size_unit = 'point';
da.mark_size = 10;
//da.mark_foreground = size(cmap, 'r') - 1;
ax = newaxes();
ax.margins = [0.07,0.07,0.03,0.07];
ax.tight_limits = 'on';
ax.data_bounds = [0.8,0.8,0.8;10.2,10.2,10.2];
ax.cube_scaling = 'on';
ax.zoom_box = [0.8,0.8,10.2,10.2,0.8,10.2];
ax.hidden_axis_color = size(cmap, 'r') - 1;
//ax.line_mode = 'off'
//ax.mark_mode = 'on'
//ax.mark_size_unit = 'point'
//ax.mark_size = 10
//ax.mark_foreground = 1

//-------------------------------------------------------------------------------
// Plot all dots as separate polylines, each having just one point, in its own colour value.
// Dot size can be used instead of dot colour.

for i = 1: size(dots, 'r') do
                param3d(dots(i, 1), dots(i, 2), dots(i, 3));
                pl = gce();
                pl.line_mode = 'off';
                pl.mark_mode = 'on';
                pl.mark_size_unit = 'point';
                pl.mark_size = 10;                                                            // Using dot colour to display the dependent variable
                pl.mark_foreground = dots(i, 4);
//            pl.mark_size = dots(i, 4);                                               // Using dot size to display the dependent variable
//            pl.mark_foreground = size(cmap, 'r') - 1;
end

//*******************************************************************************





Adrian Weeks.
Engineer, Hardware Engineering EMEA.
Office: +44 (0) 2920 528500 | Direct: +44 (0) 2920 528523
Email: aweeks at hidglobal.com

[HID Global Logo]<http://www.hidglobal.com/>
HID Global, 3 Cae Gwrydd, Green Meadow Springs, Cardiff, CF15 7AB , United Kingdom
www.hidglobal.com<http://www.hidglobal.com/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190125/3262bd10/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 2408 bytes
Desc: image001.gif
URL: <https://lists.scilab.org/pipermail/users/attachments/20190125/3262bd10/attachment.gif>


More information about the users mailing list