I know that this topic is often popping out, but after many tries, searches and give-ups, I am bringing it back to you.
I have a class, which contains a matplotlib figure. In this figure, I want a text, and when the user hits some key, the text is updated to something, without drawing all the heavy stuff in the axis. It looks like I need to blit someone here, but how? Here is a working example, the best I could get to until now.
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
class textUpdater:
def __init__(self):
self.fig, self.ax = plt.subplots()
# self.text = plt.figtext(.02, .14, 'Blibli')
self.text = self.ax.text(0, .5, 'Blabla')#, transform = self.ax.transAxes)#, animated=True)
self.fig.canvas.mpl_connect('key_press_event', self.action)
self.fig.canvas.draw()
plt.show()
def action(self, event):
if event.key == 'z':
self.text.set_text('Blooooo')
self.ax.draw_artist(self.text)
self.fig.canvas.blit(self.text.get_window_extent())
textUpdater()
First question: when bliting the thing, the previous text appears behind. I want it gone!
And second: I would in fact prefer to have it as a fig text, out of any axes. Does it sound feasible?
Your are the bests, thanks a lot.