COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### scatter plot for three variables

• Follow

```hai all there

i have one variable say 'a' which has 10 rows and 2 columns. i.e, there are 10 instances of 2 dimentional.

similarly i have anothor two variables, 'b' and 'c'. all are having 10 instances, in two dimensions.
or simply , a=rand(10,2); b=rand(10,2); c=rand(10,2).

i want to plot these a, b and c on scatter plot diagram each with different symbols or colours.

but i am not getting that. anybody can explain.

can anybody help me on this.please

```
 0

```shahnaz fatima wrote:
> hai all there
>
> i have one variable say 'a' which has 10 rows and 2 columns. i.e, there
> are 10 instances of 2 dimentional.
>
> similarly i have anothor two variables, 'b' and 'c'. all are having 10
> instances, in two dimensions.
> or simply , a=rand(10,2); b=rand(10,2); c=rand(10,2).
>
> i want to plot these a, b and c on scatter plot diagram each with
> different symbols or colours.
>
> but i am not getting that. anybody can explain.
>
> can anybody help me on this.please

scatter(a, 1, 'r');
hold on
scatter(b, 1, 'g');
scatter(c, 1, 'b');
```
 0

```thanks for the reply.
i tried to give these commands.
but i am getting error.
can you please solv emy problem.

a=rand(10,2);
>> b=rand(10,2);
>> c=rand(10,2);
>> scatter(a, 1, 'r');
??? Error using ==> scatter at 62
X and Y must be vectors of the same length.
```
 0

```> a=rand(10,2);
> >> b=rand(10,2);
> >> c=rand(10,2);
> >> scatter(a, 1, 'r');
> ??? Error using ==> scatter at 62
> X and Y must be vectors of the same length.

At a very quick reading, scatter takes two inputs to plot of the same length. You specified a of length 10 (which by the way has two columns) and 1, which is a 1 x 1 scalar. Refer to columns in your variables, e.g.
scatter(a(:,1), b(:,2), 'r')
```
 0

```> At a very quick reading, scatter takes two inputs to plot of the same length. You specified a of length 10 (which by the way has two columns) and 1, which is a 1 x 1 scalar. Refer to columns in your variables, e.g.
> scatter(a(:,1), b(:,2), 'r')

Ah, I see now, only after reading your first post, where did you take that command from. Walter focused on your main point, using different symbols or colours. Things are explained e.g. here
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/linespec.html
and there was a post a time ago where it was Walter I think to explain how to create a cell with strings or so representing symbols or colors so that you can use them in a loop.
```
 0

```thanks for reply on scatter plot
i got nice plot using.
>> scatter(a(:,1), a(:,2), 'r')
>> hold on;
>> scatter(b(:,1), b(:,2), 'g')
>> scatter(c(:,1), c(:,2), 'b')

what can i do to get the points as small * , or filled dots insted of big circles.
```
 0

```shahnaz fatima wrote:
> i tried to give these commands.
> but i am getting error.
> can you please solv emy problem.
>
> a=rand(10,2);
>>> b=rand(10,2);
>>> c=rand(10,2);
>>> scatter(a, 1, 'r');
> ??? Error using ==> scatter at 62
> X and Y must be vectors of the same length.

Sorry, the 1 is the dot size that has to appear before the color matrix.
I mentally jumped over the fact that it would be considered as the y
coordinate.
```
 0

```>  what can i do to get the points as small * , or filled dots insted of big circles.

Well, yeah, in that event .. I remember that I also hit on this problem at some point and instead used plot() that supports setting the marker size (controlling how big your * or circles etc .. are). This property is described in the link I sent you, so normally you would be able of seeing that. But as today I managed _not_to see_ something which obviously was there it is my duty to answer your question.

% black-edged circles, blank inside
plot(x,y, 'ko','LineWidth',1,'MarkerEdgeColor','k','MarkerSize',3);

% black-edged circles, red inside
plot(x,y, 'ko','LineWidth',1.5,'MarkerEdgeColor','k', 'MarkerFaceColor', 'r','MarkerSize',3);

Note that you control the thickness of edge of your symbols by line width, whereas the size of your symbols by marker size.

PS Please ML Expert, do correct me in the event scatter() supports this stuff as well or whatever typo, I'm too tired and no expert. Thanks.
```
 0

```> scatter(a, 1, 'r');
> hold on

It's good to pay attention to what Walter writes. I just now discovered that
scatter(a(:,1),a(:,2),4,'r')
will indeed work. If you replace 4 by 1 as Walter wrote, you_will_create scatter dots, but they are almost invisible and all you would think you see is a blank set of axis.
```
 0

```"shahnaz fatima" <shahnaz1981fat@gmail.com> wrote in message <hvtf1k\$3aa\$1@fred.mathworks.com>...
> hai all there
>
> i have one variable say 'a' which has 10 rows and 2 columns. i.e, there are 10 instances of 2 dimentional.
>
> similarly i have anothor two variables, 'b' and 'c'. all are having 10 instances, in two dimensions.
> or simply , a=rand(10,2); b=rand(10,2); c=rand(10,2).
>
> i want to plot these a, b and c on scatter plot diagram each with different symbols or colours.
>
> but i am not getting that. anybody can explain.
>
> can anybody help me on this.please
>

one of the many solutions

% the data
g1=rand(2,2);
g2=rand(3,2)+1;
g3=rand(5,2)+2;
cm=[[1,0,0];[0,1,0];[0,0,1]].';     % <- colors/grp
ms=[20;50;80];     % <- size/grp
% the engine
v=[g1;g2;g3];
gx=[1,size(g1,1),size(g2,1),size(g3,1)];
gx=cumsum(accumarray(cumsum(gx.'),1));
gx(end)=[];
% the result
scatter(v(:,1),v(:,2),ms(gx),cm(gx,:),'filled');

us
```
 0
Reply us1 (8054) 6/24/2010 7:00:21 PM

```thanks for the reply walter, sscnikro and us. i good good plot.
```
 0

10 Replies
328 Views

Similiar Articles:

7/24/2012 12:48:45 AM