# Regression in scatter plot?

Hi,

according to the documentation, scatter should accept a 1D float array for color kwarg. Therefore, I thought the following code would work (and I think it worked at some point in the past; I'm currently using matplotlib 0.99.0):

import numpy as N
from matplotlib import pyplot as P

x = N.random.randn(100)
y = N.random.randn(100)
z = N.random.randn(100)**2

fig = P.figure()

cmap = P.matplotlib.cm.jet
norm = P.matplotlib.colors.Normalize(vmin=0, vmax=1)

sc = ax.scatter(x,y,
color=z,
cmap=cmap,
norm=norm,
)

But this crashes with the following error:

[...]
/data/ycopin/Softs/local/lib/python2.4/site-packages/matplotlib/colors.pyc in to_rgba_array(self, c, alpha)
377 if isinstance(c, np.ndarray):
378 if c.ndim != 2 and c.dtype.kind not in 'SU':
--> 379 raise ValueError("Color array must be two-dimensional")
380 if (c.ndim == 2 and c.shape[1] == 4 and c.dtype.kind == 'f'):
381 if (c.ravel() > 1).any() or (c.ravel() < 0).any():

ValueError: Color array must be two-dimensional

So my question is: is the documentation just outdated, or is it a regression in scatter?

Cheers,

···

--
.~. Yannick COPIN (o:>* Doctus cum libro
/V\ Institut de physique nucléaire de Lyon
// \\ Université de Lyon - CNRS-IN2P3
/( )\ AIM: YnCopin ICQ: 236931013
^`~'^ http://snovae.in2p3.fr/ycopin/

Hello,

According to http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.scatter , the keyword argument that takes an array to specify the colors of the individual markers is c. color is interpreted as a color to give to all markers at once.

The following works on my computer (matplotlib 0.99.0) :

import numpy as N
from matplotlib import pyplot as P

x = N.random.randn(100)
y = N.random.randn(100)
z = N.random.randn(100)**2

fig = P.figure()

cmap = P.matplotlib.cm.jet
norm = P.matplotlib.colors.Normalize(vmin=0, vmax=1)

sc = ax.scatter(x,y,
c=z,
cmap=cmap,
norm=norm,
)

···

Le 10 déc. 09 à 14:44, Yannick Copin a écrit :

Hi,

according to the documentation, scatter should accept a 1D float array for
color kwarg. Therefore, I thought the following code would work (and I think
it worked at some point in the past; I'm currently using matplotlib 0.99.0):

import numpy as N
from matplotlib import pyplot as P

x = N.random.randn(100)
y = N.random.randn(100)
z = N.random.randn(100)**2

fig = P.figure()