9

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
2
  • please share some data so that we can try it out by ourselves. Commented Oct 27, 2020 at 11:06
  • I have added a dataframe. Commented Oct 27, 2020 at 11:38

2 Answers 2

19

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

Sign up to request clarification or add additional context in comments.

Comments

-1

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.

1 Comment

I have lowered my s, yet the same problem still occurs. I have added a dataframe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.