How to put individual tags for a scatter plot

Posted on

Question :

How to put individual tags for a scatter plot

I am trying to do a scatter plot in matplotlib and I couldn’t find a way to add tags to the points. For example:

scatter1=plt.scatter(data1["x"], data1["y"], marker="o",

I want for the points in “y” to have labels as “point 1”, “point 2”, etc. I couldn’t figure it out.

Answer #1:

Perhaps use plt.annotate:

import numpy as np
import matplotlib.pyplot as plt

N = 10
data = np.random.random((N, 4))
labels = ['point{0}'.format(i) for i in range(N)]

plt.subplots_adjust(bottom = 0.1)
    data[:, 0], data[:, 1], marker='o', c=data[:, 2], s=data[:, 3] * 1500,

for label, x, y in zip(labels, data[:, 0], data[:, 1]):
        xy=(x, y), xytext=(-20, 20),
        textcoords='offset points', ha='right', va='bottom',
        bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
        arrowprops=dict(arrowstyle = '->', connectionstyle='arc3,rad=0'))

enter image description here

Answered By: unutbu

Leave a Reply

Your email address will not be published. Required fields are marked *