[Matplotlib-users] Simultaneous plots with Matplotlib "QObject/thread" error
John Robson
John.Robson at usp.br
Fri Sep 9 17:24:08 EDT 2016
Eric, you are right, I followed this and worked:
http://matplotlib.org/faq/howto_faq.html#howto-webapp
I also fixed other problems, I was using "plt.savefig", "plt.xxx" I
believe that this "plt" was harming other simultaneous plots, so I
replaced every "plt." by ".fig" and now I think is OK.
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()
fig.set_tight_layout(True)
fig.savefig(filename, format='png', dpi=100, facecolor='w',
edgecolor='k', bbox_inches='tight')
fig.clf()
plt.close(fig)
So the first "fig" instance is destroyed at the end and there is no
"plt.xxx"
This is a good approach to isolate all plots?
Thank you,
John
On 09/09/16 03:16, Eric Firing wrote:
> On 2016/09/08 8:40 PM, John Robson wrote:
>> Hi all,
>>
>> I have some Flask pages that plot charts using Matplotlib, they work
>> very well, but when running them simultaneously they break the site,
>> with errors like:
>>
>> "QObject: Cannot create children for a parent that is in a different
>> thread."
>>
>> "QObject::~QObject: Timers cannot be stopped from another thread"
>>
>> I wonder how to safely use Matplolib with Flask (with several
>> simultaneous users plotting charts all the time)?
>
> I suspect the problem is that matplotlib is running with the qt4agg
> backend.
>
> When plotting for a web app like that, you need to make sure the backend
> is set to the agg backend. You can do that in a matplotlibrc file or
> directly in the plotting script, immediately after importing matplotlib
> and before importing pyplot (if you use pyplot at all).
>
> Eric
>
>>
>> Thank you,
>> John
More information about the Matplotlib-users
mailing list