Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing size of scattered points in matplotlib

I am doing some plotting using cartopy and matplotlib, and I am producing a few images using the same set of points with a different domain size shown in each image. As my domain size gets bigger, the size of each plotted point remains fixed, so eventually as I zoom out, things get scrunched up, overlapped, and generally messy. I want to change the size of the points, and I know that I could do so by plotting them again, but I am wondering if there is a way to change their size without going through that process another time.

this is the line that I am using to plot the points:

plt.scatter(longs, lats, color = str(platformColors[platform]), zorder = 2, s = 8, marker = 'o')

and this is the line that I am using to change the domain size:

ax.set_extent([lon-offset, lon+offset, lat-offset, lat+offset])

Any advice would be greatly appreciated!

like image 397
Jabberwock Stomp Avatar asked Sep 14 '25 15:09

Jabberwock Stomp


1 Answers

scatter has the option set_sizes, which you can use to set a new size. For example:

import matplotlib.pylab as pl
import numpy as np

x = np.random.random(10)
y = np.random.random(10)
s = np.random.random(10)*100

pl.figure()
l=pl.scatter(x,y,s=s)

s = np.random.random(10)*100
l.set_sizes(s)

It seems that set_sizes only accepts arrays, so for a constant marker size you could do something like:

l.set_sizes(np.ones(x.size)*100)

Or for a relative change, something like:

l.set_sizes(l.get_sizes()*2)

enter image description here enter image description here

like image 60
Bart Avatar answered Sep 17 '25 21:09

Bart