Home > Mobile >  Python / Seaborn - How to plot the names of each value in a scatterplot
Python / Seaborn - How to plot the names of each value in a scatterplot

Time:01-09

first of all, in case I comment on any mistakes while writing this, sorry, English is not my first language.

I'm a begginer with Data vizualiation with python, I have a dataframe with 115 rows, and I want to do a scatterplot with 4 quadrants and show the values in R1 (image below for reference)

enter image description here

If you're just working in the notebook and don't need to save the image with all the player's names, then using a "hover" feature might be a better idea. Annotating every player's name might become too busy for the graph, so just hovering over the point might work out better for you.

%matplotlib widget # place this or "%matplotlib notebook" at the top of your notebook
                   # This allows you to work with matplotlib graphs in line

import mplcursors # this is the module that allows hovering features on your graph

# using the same dataframe from above
ax1 = sns.scatterplot(x = value_1, y = value_2, s = 100)
@mplcursors.cursor(ax1, hover=2).connect("add") # add the plot to the hover feature of mplcursors
def _(sel):
    sel.annotation.set_text('Player: {}\nValue 1: {}\nValue 2: {}'.format(df.name[sel.index], sel.target[0], sel.target[0])) # set the text


    # you don't need any of the below but I like to customize
    sel.annotation.get_bbox_patch().set(fc="lightcoral", alpha=1) # set the box color
    sel.annotation.arrow_patch.set(arrowstyle='-|>', connectionstyle='angle3', fc='black', alpha=.5) # set the arrow style

Example outputs from hovering: enter image description here enter image description here

  • Related