0

I would like to make a plot in python with jitter and size as variable. I can either do a plot with size as variable (plt.scatter) or jitter (sns.stripplot)

Sample data (of course my real data is much bigger)

import pandas as pd
Test = pd.DataFrame(data = {'x': [3, 3, 3, 4], \
                            's' : [1, 4, 9, 20], \
                            't' : ["A", "B","A", "B"]})

plot with no jitter but size as variable

#Method 1 - no jitter
import matplotlib.pyplot as plt

x = Test['x']
s = Test['s']
t = Test['t']

plt.scatter(x = x, y = t, s = s* 100)

plot showing overlaping points

plot with jitter but no size distention

#Method 2 - no size
import seaborn as sns
sns.stripplot(x='x', y='t', size  = 10, data= Test, jitter=True)

plot with jitter

AAAA
  • 461
  • 6
  • 22
  • 1
    You can add jitter to the scatterplot-with-different-sizes by getting the offsets and add some random noise. See the second part of [this post](https://stackoverflow.com/a/60165124/12046409) – JohanC Feb 12 '20 at 10:02
  • @JohanC thank you! it did work. do you how to bring closer "A" and "B", values on axis? – AAAA Feb 12 '20 at 15:38
  • 1
    The y-axis is categorical, so internally 0 and 1. With `plt.ylim(-0.5,1.5)` or `plt.ylim(-0.9,1.9)` A and B should come closer together. – JohanC Feb 12 '20 at 15:52
  • @JohanC you are a true genius! thank you! – AAAA Feb 12 '20 at 17:50

0 Answers0