1

I have the following code to annotate a plot made with matplotlib:

for i,j in data.items():
   ax.annotate(str(j), xy=(i, j))

This annotates every point on a very point dense plot. Is there anyway to only put an annotation or label on every nth point?

1
  • You could add an arbitrary counter that gets increased every iteration. And you put that ax.annotate(...) inside an if counter % 50 == 0 to annotate every 50th point. The counter could be added manually or by using enumerate. Commented May 30, 2018 at 17:27

1 Answer 1

2

As suggested in my comment:

for count, (i,j) in enumerate(data.items()):
    if count % 50 == 0:
        ax.annotate(str(j), xy=(i, j))

Replace 50 with a different integer if you don't want to annotate every 50'th point.

Sign up to request clarification or add additional context in comments.

Comments

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.