I want to be able to freely change a matplotlib plot. I'm doing this by finding the Artist
objects in a plot (which are responsible for drawing everything) but I can't update the text.
For example, here I attempt to change the magnitude text. I can update the color and position but not the text like I want to.
import matplotlib.pyplot as plt
# Make the plot
data = [1e6 + i for i in range(10)]
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.plot(data)
plt.title("Normal")
plt.subplot(1, 2, 2)
plt.plot(data)
plt.title("Updated Artist")
plt.draw()
# Find all `Text` Artist objects in the current axis
t = plt.gca().findobj(plt.Text)
# Filter them to get the one with the text we want
t = next(filter(lambda x: x.get_text() == '+1e6', t))
# Update the position
pos = t.get_position()
pos = (pos[0]+0.1, pos[1])
t.set_position(pos)
# Set properties
t.set_text('1,000,000') # This doesn't work! :(
t.set_color('red')
plt.show()