pyplot scatter width code example

Example 1: python scatter size

This can be a somewhat confusing way of defining the size but you are basically specifying the area of the marker. This means, to double the width (or height) of the marker you need to increase s by a factor of 4. [because A = WH => (2W)(2H)=4A]

There is a reason, however, that the size of markers is defined in this way. Because of the scaling of area as the square of width, doubling the width actually appears to increase the size by more than a factor 2 (in fact it increases it by a factor of 4). To see this consider the following two examples and the output they produce.

Example 2: matplotlib units of scatter size

star = MarkerStyle('*')
bbox = star.get_path().transformed(star.get_transform()).get_extents()
star_unit_width = bbox.width
star_unit_height = bbox.height
plt.scatter(0, -1, marker='s', s=(xscale*desired_data_width/star_unit_width)**2)