Benjamin Root <ben.root@...83...> writes:

<snip>

Probably not directly, but I hadn't thought about that before. For a set of

scatter points that are colored by values, what should the legend show? In

other words, what does it *mean* for there to be a legend for points that are

colored in a potentially non-uniform manner?So, maybe this is desired behavior

(but possibly by accident)?

Thanks for your help,

Ben Root

I thought for a moment that legend was using the color of the first point in the

set, but a quick test reveals that no matter what colormap you specify, the

marker color inside the legend is blue. BTW, I think I've found another thing

related to legend() and scatter plots: the 'numpoints' keyword argument to

legend is not respected, as showed in the example pasted below,

Jorge

## ···

-------

import numpy as np

import matplotlib as mpl

import matplotlib.pyplot as plt

data0 = np.random.rand(10,2)

data1 = np.random.rand(10,2)

data2 = np.random.rand(10,2)

data = [data0, data1, data2]

fig, ax = plt.subplots(1,1)

norm = mpl.colors.Normalize(0,len(data))

cmap = mpl.cm.afmhot

sc = []

labels = []

for i,d in enumerate(data):

sc.append(ax.scatter(d.T[0], d.T[1], c=np.ones(d.shape[0])*i,

norm=norm, cmap=cmap))

labels.append('data set ' + str(i))

ax.legend(sc, labels, numpoints=1)

plt.show()

-------