pylab plot problem

I didn't understand why i can not see 20 dots with the below command,
but i just see 3 dots at the graph.

import pylab as P
import numpy as N

a1 = N.ndarray(shape=(10,2))*2

x = a1[:,0]
y = a1[:,1]

a2 = N.ndarray(shape=(10,2))+10
xx = a2[:,0]
yy = a2[:,1]

n_x = N.append(x,xx)
n_y = N.append(y,yy)

P.scatter(n_x, n_y, alpha=0.5)
P.xlim(xmin=n_x.min()*10, xmax=n_x.max()*10)
P.ylim(ymin=n_y.min()*10, ymax=n_y.max()*10)

P.plot(n_x, n_y, 's', alpha=0.7, ms=3)

P.show()

Normally i have 20 different points to be plotted but because they are
so close values it just plots three of them. Any idea how i can fix
it?

Hi Oğuz,

Oğuz Yarımtepe, on 2011-04-13 23:09, wrote:

I didn't understand why i can not see 20 dots with the below command,
but i just see 3 dots at the graph.

a1 = N.ndarray(shape=(10,2))*2

When you allocate an array this way - you're just allocating
space for it without initializing it to anything - there are no
guarantees about what values that array will take on - and on
most operating systems it will vary from one run to another.

If you're trying to get a random number, changes the a1 and a2
lines to:

a1 = N.random.rand(10,2)*2
a2 = N.random.rand(10,2)+10

P.xlim(xmin=n_x.min()*10, xmax=n_x.max()*10)
P.ylim(ymin=n_y.min()*10, ymax=n_y.max()*10)

I don't think you want to do n_x.min()*10 - multiplying the min
and max values has a different effect on the limits depending on
the sign of those values. You probably want to find the
difference between min and max and then use that to extend and
limits, instead.

Normally i have 20 different points to be plotted but because they are
so close values it just plots three of them. Any idea how i can fix
it?

The fact that you weren't initializing your arrays with anything
affects how many unique combinations of x and y you'll have.
len(set(zip(n_x,n_y))) will tell you how many points you should
see.

best,

···

--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7