Show labels for each element when drawing scatter plots in Pandas

Notes on drawing scatter plots in Pandas

It's pretty easy to find a way to draw a scatter plot in Pandas. However, I couldn't find a way to display the label on each element as shown below, so make a note of it.

scatter-simple-text.png

Repeat each row with for in Pandas iterrows () until drawing with aanotate.

scatter-label.py


import pandas as pd

#Set data in DataFrame
dd = pd.DataFrame([
        [10,50,'hoge'],
        [50,30,'fpp'],
        [20,30,'baa']
    ], columns=['ax','ay','label'])

#Draw a scatter plot
a = dd.plot.scatter(x='ax',y='ay')
#Display a label on each element
for k, v in dd.iterrows():
    a.annotate(v[2], xy=(v[0],v[1]), size=15)

Recommended Posts

Show labels for each element when drawing scatter plots in Pandas
Precautions when using for statements in pandas
Behavior in each language when coroutines are reused with for
Manage the overlap when drawing scatter plots with a large amount of data (Matplotlib, Pandas, Datashader)