-1

I am creating a scatter plot, where in points are very close to each other. I am labelling each points but labels are overlapping each other other and making it difficult to read. So is there a way we can take labels outside the figure by drawing lines. I have pasted the expected o/p below.

enter image description here

In above image 'X' are points, 'L' are labels, and square box is the figure. Any thoughts or suggestions.

pykarthick
  • 11
  • 3

1 Answers1

1

Here are two different ways to do it, one outside of the axes area and two inside:

x = np.arange(5)
y = np.random.rand(5)
fig, ax = plt.subplots()
ax.scatter(x, y)
arrow1 = ax.annotate("Test 1", xy=(x[1], y[1]), xycoords="data", xytext=(x[1], 1.05), textcoords=("data", "axes fraction"), va="center", ha="left", arrowprops=dict(arrowstyle="->", color='b'))
arrow2 = ax.annotate("Test 2", xy=(1, 1), xycoords=ax.annotate('', xy=(x[2],y[2])), xytext=(30, 0), textcoords="offset points", va="center", ha="left", arrowprops=dict(arrowstyle="->"))

Output:

enter image description here

Karina
  • 1,252
  • 2
  • 5
  • 16