Hey I spend a good amount at google but couldn't find a solution for this:
I'm plotting a graph embededded in a pygame window using a non-gui-backend:
import matplotlib as mpl
mpl.use("Agg")
import matplotlib.backends.backend_agg as agg
import matplotlib.pyplot as plt
fig = plt.figure(num=3, figsize=[3.5, 2.6], # Inches
dpi=100, # 100 dots per inch, so the resulting buffer is 400x400 pixels
)
x = [1,2,3]
y = [1,2,3]
ax = fig.gca()
plt.step(x, y, 'r')
canvas = agg.FigureCanvasAgg(fig)
canvas.draw()
renderer = canvas.get_renderer()
raw_data = renderer.tostring_rgb()
screen = pygame.display.get_surface()
size = canvas.get_width_height()
surf = pygame.image.fromstring(raw_data, size, "RGB")
screen.blit(surf, (0,pictureSize_y))
Now I want to create a new window plotting different data. I always get the Error:
UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure
I tried it with this Post which leads to this:
RuntimeError: main thread is not in main loop
So ist there any way to use both?