jadedQuail
jadedQuail

Reputation: 89

How do I move each marker label in a matplotlib graph?

Below I have a simple script for a graph:

import matplotlib.pyplot as plt

days = ["Monday", "Tuesday", "Wednesday"]
values = [10, 15, 30]
labels = ["A", "B", "C"]

fig, ax = plt.subplots()
ax.plot(days, values, marker = 'o')

for i, txt in enumerate(labels):
    text = ax.annotate(txt, (days[i], values[i]), fontsize=20)

plt.show()

Which creates the following chart: enter image description here

I would like to move over the labels on the data markers (A, B, and C) to the right by N degrees each. How would I accomplish this based on relative position of each marker?

Upvotes: 0

Views: 757

Answers (1)

norie
norie

Reputation: 9857

Not sure about degrees but you could use something like this to move the text 10pts to the right and 10pts down.

for i, txt in enumerate(labels):
    text = ax.annotate(txt, (days[i], values[i]), fontsize=20, textcoords="offset points", xytext=(10,-10))

Upvotes: 1

Related Questions