Scott Adamson
Scott Adamson

Reputation: 415

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

Upvotes: 9

Views: 13742

Answers (2)

StupidWolf
StupidWolf

Reputation: 46978

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

Upvotes: 19

Mitchell van Zuylen
Mitchell van Zuylen

Reputation: 4135

The parameter s=200 sets the individual scatter points to a very large size. Adding 4 points of jitter is very little compared to that.

Upvotes: -1

Related Questions