Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

add name of people to the scatterplot

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

_, 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)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading