[Flask] Simultaneous Matplotlib "QObject" error

Andrea D'Amore and.damore at gmail.com
Sat Sep 10 03:59:45 EDT 2016

On 9 September 2016 at 23:26, John Robson <John.Robson at usp.br> wrote:

> I also fixed other problems, I was using "plt.savefig", "plt.xxx" I believe
that this "plt" was harming other simultaneous plots,

It's hard to figure what was happening without seeing the code.
The pyplot interface is just a state on the object-oriented, more
general, one; this way you get to quickly call the "current" figure or
axes, but it's nothing more magic than this.
I suggest using the object-oriented api and keeping the objects you
need in your code, it makes things much clearer.

> so I replaced every "plt." by ".fig" and now I think is OK.

That doesn't look right, as it's written.

> I just wonder how can I isolate each plot from other simultaneous plots, I'm
doing this:
> fig = plt.figure()
> ax = fig.gca()
> plot stuff, scatterplot, etc..., set title, lables, etc...
> fig = ax.get_figure()
> So the first "fig" instance is destroyed at the end

The first "instance" is the same as last, from what you wrote you got
a figure, then its axes, then again this axes' figure that is of
course the same object you started with.

> fig.clf()
> plt.close(fig)
> and there is no "plt.xxx"

There clearly is the plt.close() call at the end.

> This is a good approach to isolate all plots?

What do you mean by "isolate all plots" there?

When I had to generate many image files I felt more natural keep the
Figure instance in the loop that called savefig(), I only changed the
plot in the "central" axes thus keeping the common layout to all


More information about the Flask mailing list