2013-02-12 07:37:29 8 Comments

In the pyplot document for scatter plot:

```
matplotlib.pyplot.scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None,
vmin=None, vmax=None, alpha=None, linewidths=None,
faceted=True, verts=None, hold=None, **kwargs)
```

The marker size

s: size in points^2. It is a scalar or an array of the same length as x and y.

What kind of unit is `points^2`

? What does it mean? Does `s=100`

mean `10 pixel x 10 pixel`

?

Basically I'm trying to make scatter plots with different marker sizes, and I want to figure out what does the `s`

number mean.

### Related Questions

#### Sponsored Content

#### 17 Answered Questions

### [SOLVED] How to put the legend out of the plot

**2011-01-15 16:10:03****pottigopi****878410**View**1049**Score**17**Answer- Tags: python matplotlib legend

#### 20 Answered Questions

### [SOLVED] Save plot to image file instead of displaying it using Matplotlib

**2012-03-08 17:38:10****Homunculus Reticulli****1716608**View**1211**Score**20**Answer- Tags: python matplotlib plot

#### 17 Answered Questions

### [SOLVED] How do you change the size of figures drawn with matplotlib?

**2008-12-01 21:24:44****tatwright****3024047**View**2194**Score**17**Answer- Tags: python graph matplotlib plot visualization

#### 1 Answered Questions

### [SOLVED] Making a scatter marker as large as the Axes

**2019-08-28 16:25:42****L. B.****27**View**0**Score**1**Answer- Tags: python matplotlib

#### 1 Answered Questions

### [SOLVED] ValueError: x and y must be the same size when drawing ax[i].scatter in plt.subplots()

**2019-05-23 02:13:57****Bowen Peng****91**View**0**Score**1**Answer- Tags: python matplotlib

#### 3 Answered Questions

### [SOLVED] Controlling alpha value on 3D scatter plot using Python and matplotlib

**2013-03-20 19:45:42****coderunner****5510**View**17**Score**3**Answer- Tags: python numpy matplotlib

#### 3 Answered Questions

### [SOLVED] Python scatter plot. Size and style of the marker

**2012-01-31 14:50:00****Brian****94163**View**39**Score**3**Answer- Tags: python plot matplotlib scatter

#### 1 Answered Questions

### [SOLVED] plotting list of tuples (x coord, y coord, color) with pyplot.scatter() method

**2015-05-12 12:25:21****Dennis****2949**View**1**Score**1**Answer- Tags: python matplotlib plot

## 6 comments

## @Dan 2013-02-13 18:59:40

This can be a somewhat confusing way of defining the size but you are basically specifying the

areaof 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.

gives

Notice how the size increases very quickly. If instead we have

gives

Now the apparent size of the markers increases roughly linearly in an intuitive fashion.

As for the exact meaning of what a 'point' is, it is fairly arbitrary for plotting purposes, you can just scale all of your sizes by a constant until they look reasonable.

Hope this helps!

Edit:(In response to comment from @Emma)It's probably confusing wording on my part. The question asked about doubling the width of a circle so in the first picture for each circle (as we move from left to right) it's width is double the previous one so for the area this is an exponential with base 4. Similarly the second example each circle has

areadouble the last one which gives an exponential with base 2.However it is the second example (where we are scaling area) that doubling area appears to make the circle twice as big to the eye. Thus if we want a circle to appear a factor of

`n`

bigger we would increase the area by a factor`n`

not the radius so the apparent size scales linearly with the area.Editto visualize the comment by @TomaszGandor:This is what it looks like for different functions of the marker size:

## @Emma 2013-10-22 20:20:34

I'm probably misunderstanding your point, but in your second example you are increasing s exponentially (s=[20, 40, 80, 160, 320, 640]) and saying that that gives us a nice linear-looking size increase. Wouldn't it make more sense if increasing the size linearly (ex. s=[20, 40, 60, 80, 100, 120]) gave us the linear-looking result?

## @Dan 2013-10-22 22:00:28

@Emma Your intuition is right, it's poor wording on my part (alternatively poor choice of x axis scaling). I explained some more in an edit because it was too long for a comment.

## @Sigur 2017-05-10 17:35:46

Is it possible to change

`s`

value according to the size of figure window? I mean, if we maximize the figure windows, I'd like to have bigger size marks.## @Tomasz Gandor 2019-06-13 11:35:29

Great example (just the necessary stuff!). This should not be

`4 ** n`

and`2 ** n`

, but`n ** 4`

and`n ** 2`

. With`2 ** n`

the second plot does not scale linearly in terms of circle diameter. It still goes too fast (just not that much over the top).## @Tomasz Gandor 2019-06-13 11:39:18

To put it shorter - the second plot shows square root of exponential - which is another exponential, just a bit less steep.

## @aerijman 2019-09-19 17:55:52

Anyone knows why, only

`s`

works but not`markersize`

as stated in the documentation?## @ImportanceOfBeingErnest 2017-11-21 00:49:20

Because other answers here claim that`s`

denotes the area of the marker, I'm adding this answer to clearify that this is not necessarily the case.## Size in points^2

The argument

`s`

in`plt.scatter`

denotes the`markersize**2`

. As the documentation saysThis can be taken literally. In order to obtain a marker which is x points large, you need to square that number and give it to the

`s`

argument.So the relationship between the markersize of a line plot and the scatter size argument is the square. In order to produce a scatter marker of the same size as a plot marker of size 10 points you would hence call

`scatter( .., s=100)`

.## Connection to "area"

So why do other answers and even the documentation speak about "area" when it comes to the

`s`

parameter?Of course the units of points**2 are area units.

`marker="s"`

, the area of the marker is indeed directly the value of the`s`

parameter.`area = pi/4*s`

.In all cases however the area of the marker is proportional to the. This is the motivation to call it "area" even though in most cases it isn't really.`s`

parameterSpecifying the size of the scatter markers in terms of some quantity which is proportional to the area of the marker makes in thus far sense as it is the area of the marker that is perceived when comparing different patches rather than its side length or diameter. I.e. doubling the underlying quantity should double the area of the marker.

## What are points?

So far the answer to what the size of a scatter marker means is given in units of points. Points are often used in typography, where fonts are specified in points. Also linewidths is often specified in points. The standard size of points in matplotlib is 72 points per inch (ppi) - 1 point is hence 1/72 inches.

It might be useful to be able to specify sizes in pixels instead of points. If the figure dpi is 72 as well, one point is one pixel. If the figure dpi is different (matplotlib default is

`fig.dpi=100`

),While the scatter marker's size in points would hence look different for different figure dpi, one could produce a 10 by 10 pixels^2 marker, which would always have the same number of pixels covered:

If you are interested in a scatter in data units, check this answer.

## @Anatoly Alekseev 2018-12-26 19:56:41

Wondering how would one calculate what s parameter to give to scatter to get a circle which covers diameter of, let's say, 0.1 in real coordinates of the plot (so as to fill the gap between let's say 0.4 and 0.5 on a plot from (0,0) to (1,1)?

## @ImportanceOfBeingErnest 2019-02-17 04:28:57

@AnatolyAlekseev That should be answered by this question.

## @Joaquin 2016-04-20 19:24:33

It is the

areaof the marker. I mean if you have`s1 = 1000`

and then`s2 = 4000`

, the relation between the radius of each circle is:`r_s2 = 2 * r_s1`

. See the following plot:I had the same doubt when I saw the post, so I did this example then I used a ruler on the screen to measure the radii.

## @Ayan Mitra 2020-04-29 17:13:50

This is the cleanest and most fat free answer. Thanks

## @Ike 2017-06-05 18:20:46

I also attempted to use 'scatter' initially for this purpose. After quite a bit of wasted time - I settled on the following solution.

This is based on an answer to this question

## @grabantot 2018-04-16 06:32:24

very helpfull. But why use two loops?

## @Ike 2018-04-16 12:04:18

@grabantot no reason, just didn't think too much into it.

## @zhaoqing 2017-04-13 06:54:20

You can use

markersizeto specify the size of the circle in plot methodFrom here

## @Dom 2017-04-28 09:19:25

The question was about scatterplot, and in matplotlib the two plotting functions have different parameters (

markersizeforplot, andsforscatter). So this answer doesn't apply.## @Przemek D 2017-07-26 08:18:27

@Dom I upvoted, because this question pops up as the first result in google even when I search "pyplot plot marker size", so this answer helps.

## @zhaoqing 2017-07-28 05:42:37

I know the plot method and the scatter method are different in plt but they both can realize the 'scatter plot' and adjust markersize, so this answer is just another working around if you use plot method @Dom

## @user34028 2015-05-26 20:47:22

If the size of the circles corresponds to the square of the parameter in

`s=parameter`

, then assign a square root to each element you append to your size array, like this:`s=[1, 1.414, 1.73, 2.0, 2.24]`

such that when it takes these values and returns them, their relative size increase will be the square root of the squared progression, which returns a linear progression.If I were to square each one as it gets output to the plot:

`output=[1, 2, 3, 4, 5]`

. Try list interpretation:`s=[numpy.sqrt(i) for i in s]`

## @Sigur 2017-05-05 01:36:36

Should be

`i in output`

shouldn't?