Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn scatterplot size and jitter

I have the following code for a scatter graph

dimens = (12, 10)
fig, ax = plt.subplots(figsize=dimens)
sns.scatterplot(data = information, x = 'latitude', y = 'longitude', hue="genre", s=200,
                x_jitter=4, y_jitter=4, ax=ax)

No matter what I change the jitter to, the plots still remain very close. Whats wrong with it?

Example dataframe:

 store      longitude       latitude      genre
mcdonalds    140.232323      40.434343     all
kfc          140.232323      40.434343     chicken
burgerking   138.434343      35.545433     burger
fiveguys     137.323984      36.543322     burger
like image 419
Scott Adamson Avatar asked May 13 '26 15:05

Scott Adamson


1 Answers

In the help page, it writes:

{x,y}_jitterbooleans or floats Currently non-functional

You can either add a new column or do it on the fly:

import seaborn as sns
import pandas as pd
import numpy as np

information = pd.DataFrame({'store':['mcdonalds','kfc','burgerking','fiveguys'],
                   'longitude':[140.232323,140.232323,138.434343,137.323984],
                   'latitude':[40.434343,40.434343,35.545433,36.543322],
                   'genre':['all','chicken','burger','burger']})

def jitter(values,j):
    return values + np.random.normal(j,0.1,values.shape)

sns.scatterplot(x = jitter(information.latitude,2), 
                y = jitter(information.longitude,2),
                hue=information.genre,s=200,alpha=0.5)

enter image description here

like image 199
StupidWolf Avatar answered May 15 '26 06:05

StupidWolf