Jakub M.
Jakub M.

Reputation: 33817

matplotlib: scatter and colorbar values

I have data:

values = np.array( [0,1,2,3,4,5] )

I want to plot values as pyplot.scatter with different sizes and colours. Also, I want to resize the dots so the smallest dots are well visible.

If I do:

sc = pyplot.scatter ( pos_x, pos_y, values )
pyplot.colorbar( sc )

then I get the proper values and colors, but the smallest dots are too small. Now if I do:

values_scaled = (values * 2 + 1)
sc = pyplot.scatter ( pos_x, pos_y, values_scaled )
pyplot.colorbar( sc )

then the dots have acceptable sizes (although a bit fake) but the colorbar legend starts at 1 and ends at 11, which I don't want. I want to scale just sizes of the dots, but not the values assigned there. How to do that?

Upvotes: 0

Views: 797

Answers (1)

Chris
Chris

Reputation: 46306

The matplotlib.pyplot.scatter functions takes an optional keyword argument s, which is the "size in points^2. It is a scalar or an array of the same length as x and y". So just pass your values_scaled array as the value of this argument and leave the colour data (the optional c keyword argument) as values, i.e.:

sc = pyplot.scatter(pos_x, pos_y, c=values, s=values_scaled)

Upvotes: 1

Related Questions