How to change marker size based on the values of multiple columns
I need to do a scatter plot, where the the size of each dot is determined by the quantity of xy
.
Sample data is Student Performance Data Set: student-mat.csv
import pandas as pd
import seaborn as sns
data =\
{'traveltime': [2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 3, 1, 2, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 3, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 3, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 2, 1, 1, 1, 1, 3, 3, 1, 2, 2, 2, 1, 4, 2, 1, 1, 1, 1, 3, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 3, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 2, 1, 2, 1, 1, 2, 2, 1, 1, 3, 1, 2, 2, 1, 1, 2, 3, 2, 1, 1, 1, 2, 3, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 4, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 1, 3, 2, 1, 2, 2, 2, 2, 3, 2, 2, 1, 2, 2, 2, 3, 2, 3, 2, 3, 1, 1, 2, 4, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 1, 1, 2, 1, 2, 1, 3, 1],
'G2': [6, 5, 8, 14, 10, 15, 12, 5, 18, 15, 8, 12, 14, 10, 16, 14, 14, 10, 5, 10, 14, 15, 15, 13, 9, 9, 12, 16, 11, 12, 11, 16, 16, 10, 14, 7, 16, 16, 12, 13, 10, 12, 18, 8, 10, 8, 12, 19, 15, 7, 13, 13, 11, 10, 13, 9, 15, 15, 10, 16, 11, 8, 10, 9, 10, 15, 13, 7, 9, 16, 15, 10, 6, 12, 12, 9, 11, 11, 8, 5, 12, 10, 6, 15, 10, 9, 7, 14, 10, 6, 7, 17, 6, 10, 13, 10, 15, 9, 14, 9, 7, 17, 13, 6, 18, 11, 8, 18, 13, 15, 19, 10, 13, 19, 9, 15, 13, 14, 7, 13, 15, 14, 13, 11, 7, 13, 10, 8, 4, 18, 0, 0, 13, 11, 0, 0, 0, 0, 12, 16, 9, 9, 11, 14, 0, 11, 7, 11, 6, 9, 5, 13, 10, 0, 11, 8, 12, 8, 15, 12, 6, 9, 0, 10, 8, 11, 10, 15, 7, 14, 5, 15, 11, 7, 11, 9, 13, 5, 8, 10, 8, 13, 17, 9, 13, 12, 12, 15, 7, 9, 12, 8, 8, 9, 14, 15, 15, 9, 18, 9, 16, 10, 9, 6, 10, 9, 7, 12, 9, 7, 8, 12, 13, 7, 10, 15, 6, 6, 7, 10, 6, 5, 16, 13, 13, 8, 15, 11, 8, 10, 13, 11, 9, 13, 7, 9, 13, 12, 11, 7, 12, 11, 0, 12, 0, 18, 12, 8, 5, 15, 8, 10, 9, 9, 12, 9, 12, 11, 14, 9, 18, 8, 12, 9, 10, 17, 9, 10, 9, 0, 9, 14, 11, 14, 10, 12, 9, 9, 8, 11, 8, 9, 12, 9, 9, 10, 18, 12, 14, 13, 11, 15, 12, 18, 13, 12, 9, 8, 13, 15, 10, 11, 12, 17, 14, 12, 18, 9, 12, 10, 9, 12, 11, 10, 13, 11, 8, 10, 11, 11, 13, 9, 11, 14, 15, 12, 15, 10, 9, 14, 8, 14, 0, 8, 9, 15, 13, 8, 15, 10, 12, 10, 15, 8, 10, 13, 15, 10, 15, 13, 7, 13, 7, 8, 11, 9, 13, 12, 10, 16, 13, 12, 11, 15, 11, 10, 13, 6, 10, 12, 7, 12, 11, 5, 18, 8, 14, 9, 15, 10, 14, 6, 11, 5, 5, 9, 5, 5, 9, 5, 9, 16, 8, 12, 9]}
df = pd.DataFrame(data=data)
sns.scatterplot(data=df, x="traveltime", y="G2", s=100)
This code changes the sizes of all dots.
I've tried setting size to xy
values, but it didn't work
Comments
Post a Comment