devarena logo
Reading Time: 2 minutes

In this post we will see how to change marker size of a seaborn scatterplot. It means, uniformly changing size of all points. This is just for convenience or looks, and does not add any value to the plot.

Do not confuse this with the “size” parameter which is passed to the scatterplot. The size parameter is to add an extra dimension in terms of size. In that case, individual marker points will be of varying sizes depending on the column it represents.

Let us get back to changing size of all marker points.

Syntax:

seaborn.scatterplot(data=data, x=column_name, y=column_name, s=value)

Size can be set by passing value to the “s” parameter.

The parameter “s” is a matplotlib parameter. The “s” will be treated as **kwargs when you pass it in seaborn. Default value of s is 36. You can increase or decrease this number to get bigger or smaller markers respectively.

Example

import numpy as np
import pandas as pd
import seaborn as sns
sns.set_theme(style="darkgrid")

Last line in the above code “set_theme” will only work in seaborn version 0.11 and above. If you are using a lower version, you can ignore this line.

x = np.arange(10)
y = x**2
df = pd.DataFrame({"x":x, "y":y}, columns=["x", "y"])

Default scatterplot

Below is the scatterplot with default size.

sns.scatterplot(data=df, x="x", y="y")
seaborn scatterplot with default marker size

Seaborn scatterplot – change marker size

The default marker size is 36. You can pass any number to “s”. I am using s=200.

sns.scatterplot(data=df, x="x", y="y", s=200)
seaborn scatterplot change marker size
seaborn scatterplot change marker size

Passing size as array

You can also pass an array-like values to “s” parameter, so that the markers pick the size in order mentioned in the array. I am not sure about the purpose of this usage. But it is good to know that this feature exists.

sns.scatterplot(data=df, x="x", y="y", s=[100, 150, 200, 250, 300, 350, 400, 450, 500, 550])
seaborn scatterplot change marker size - using array of size
seaborn scatterplot change marker size – using array of size

For complete list of parameters in seaborn scatterplot, please refer the seaborn documentation – seaborn.scatterplot.

Further Reading

Thanks for reading my post. If you find this helpful, please consider following this website on Youtube / Facebook / Twitter / Linkedin.

(Image by A_Different_Perspective from Pixabay)

Source link

Spread the Word!