1

I have a scatter plot that looks like this:

enter image description here

I can use the following code to add text from a list to every scatter point:

# Add text names to the plot
for i, txt in enumerate(names):
    ax.annotate(txt, (x[i],y[i]), alpha=0.6)

However I only want to annotate the points that are past 2 on the x-axis and above 2 on the y-axis. How do I go about doing that? The Matplotlib documentation doesn't give me information on marking specific points unless I already know exactly which ones I want to edit (In this case, I don't).

2 Answers 2

1

Maybe you are asking to annotate all points after 2 on the x-axis and all points after 2 on the y-axis. If so, this is the way to do:

for i, txt in enumerate(names): 
    if x[i] > 2 or y[i] > 2: 
        # annotate only if a point is having either x > 2 or y > 2.
        ax.annotate(txt, (x[i], y[i]), alpha=0.6)
Sign up to request clarification or add additional context in comments.

1 Comment

Funnily enough that did it! I don't know why I didn't consider it myself. Thank you!
1

You could try checking the values of the points before annotating them.

For example

for i, txt in enumerate(names):
    if x[i] > 2 and y[i] > 2:
         ax.annotate(txt, (x[i], y[i]), alpha=0.6)

3 Comments

I tried that, but it only gave me the names for the points to the top-right of the main 'cloud' of points, nowhere else
Perhaps you are misunderstanding each other in terms of order of operations in the phrase "points that are past 2 on the x-axis and above 2 on the y-axis". Try the condition x[i] > 2 or y[i] instead?
That did it, don't know why I didn't consider it myself, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.