Search code examples
matlabplotpointscilab

How to expand the axes of a plot with multiple points in Scilab?


I am using Scilab 5.5.2. to plot multiple points. That's my script trying to plot 4 points in 2D:

u = [1,2;2,1;3,1;4,5;5,1]

clf; plot(u,"*r")

The points I am trying to plot in 2D are (1,2), (2,1), (3,1) and (5,1).

I am using "u" as vector to store the coordinates. This script generates this image:

enter image description here

I would like to expand the x axis and the y axis in order to have an "usual" graph. I tried doing that with this:

x=[0:10]

u = [1,2;2,1;3,1;4,5;5,1]

clf; plot(x,u,"*r")

However, I get this error message:

WARNING: Transposing row vector X to get compatible dimensions
 !--error 10000 
plot: Wrong size for input arguments #2 and #3: Incompatible dimensions.
at line     147 of function checkXYPair called by :  
at line     236 of function plot called by :  
clf; plot(x,u,"*r")
at line       9 of exec file called by :    
exec('poole-exemple.sci')

What's more, there is something weird with my plot. My script generates points that I do not want. If you look at the image, you will see a (4,4) or a (1,1) point on the plot. I do not want this and I don't know why this happens.

Does anyone know how to help me?


Solution

  • Data bounds

    You want to change the data bounds, which is one of many axes properties accessible after executing gca, "get current axes". Like this:

    plot(u(:,1), u(:, 2), "*r" )
    a = gca()
    a.data_bounds = [0 0; 10 7]
    

    The format of data_bounds property is [xmin, ymin; xmax, ymax].

    And here is a better way to set it, based on the data:

    a.data_bounds = [min(u, 'r') - 1; max(u, 'r') + 1]
    

    This sets the minimum bound to the smallest data value - 1, and maximum to the largest value + 1.

    Incorrect points

    The documentation explains that the parameters of plot command are: vector of x values and vector of y values: separately, not in one matrix. With your data it should be

    plot(u(:,1), u(:, 2), "*r" )
    

    not plot(u, "*r").