I have a dataset of 6 people, which is called df
| People | Height | weight |
|---|---|---|
| Neil | 186 | 90 |
| Olaf | 187 | 60 |
| Jake | 188 | 75 |
| Mitt | 189 | 77 |
| Gaby | 181 | 62 |
| Sam | 180 | 65 |
Now I would like to to do a scatterplot which shows the name of the people in above left of the point in the scatterplot. but i don’t get the name of the people.
I did these
_, ax=plt.subplots(figsize=(5,5))
s = sns.scatterplot(x=df['Height'], y=df['weight'], ax=ax)
g.set(xlabel='height', ylabel='weight')
plt.title("relationship between height and weight");
>Solution :
You can do this using plotly (question does not state a certain library):
import plotly.express as px
import pandas as pd
df = pd.DataFrame.from_dict(
{
"People": {0: "Neil", 1: "Olaf", 2: "Jake", 3: "Mitt", 4: "Gaby", 5: "Sam"},
"Height": {0: 186, 1: 187, 2: 188, 3: 189, 4: 181, 5: 180},
"weight": {0: 90, 1: 60, 2: 75, 3: 77, 4: 62, 5: 65},
}
)
px.scatter(
df,
x="Height",
y="weight",
text="People",
height=500,
width=500,
title="relationship between height and weight",
).update_traces(textposition="top left", textfont_size=18)
