How to change the point size for regplot(), seaborn's scatter plot function (python)
To do this you can feed the regplot()
function the scatter_kws
arg like so:
import seaborn as sns
tips = sns.load_dataset('tips')
sns.regplot(x='total_bill', y='tip', data=tips,
marker='o', color='red', scatter_kws={'s':2})
sns.regplot(x='total_bill', y='tip', data=tips,
marker='o', color='red', scatter_kws={'s':20})
You could even make the points dynamically sized to represent a third dimension. This code uses the same data as the OP, but wraps it in a DataFrame (as seaborn is designed for that) and also adds a third dimension, z.
import seaborn as sns
import pandas as pd
data = pd.DataFrame({
'x': [x for x in range(5)],
'y': [1, 3, 4, 2, 5],
'z': [14, 14, 100, 16, 36]
})
sns.regplot(x='x', y='y', data=data, marker='o', color='red',
scatter_kws={'s': data['z']})
You can probably imagine how you could also manipulate the list/array of sizes programatically, giving you a lot of power to convey extra information.
I would add to mburke05's answer that it appears possible to pass array-like data into scatter_kws.
For example, if you wanted the size
attribute in the tips dataset to determine the size of a point you can write:
sns.regplot(
x="total_bill", y="tip", data=tips,
marker='o', color='red', scatter_kws={'s':tips['size']})
However, you must explicitly lookup that attribute in the dataframe (as above); you cannot simply use the column name as you would when setting x
and y
.