[Python] Should plt.ion() eliminate the need for plt.show()?

Discussão em 'Python' iniciado por Stack, Julho 14, 2025.

  1. Stack

    Stack Membro Participativo

    I was using matplotlib's Tk back end on Spyder and never had to issue plt.show() (or more specifically, plt.show(block=False)). I now have to prepare for analysis work on a closed system where the only access to Python is via QGIS. From much Googling, my impression is that the Qt back end is foundational to QGIS. This corroborates with the fact that matplotlib.use('TkAgg') yields the message:


    ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'qt' is currently running
    ​

    I sought other ways to avoid the constant need to repeatedly type plt.show(block=False). The ion() method provides an example, from which it seems that (say) with plt.ion(): plt.plot([1,2],[3,4]) should create a figure window immediately. It doesn't. Even issuing plt.show() doesn't make the figure window appear. However, plt.plot([1,2],[3,4]); plt.show(block=False) does create the plot right away.

    What am I not understanding about the ion() documentation example?

    P.S. Considering that Qt is foundational to QGIS, I do not want to venture down the path of creating a QGIS startup script that sets the back end to Tk. I'm a complete newbie to QGIS and only want to use it for it's Python support (and I'm not all that much of a Python veteran either).

    Continue reading...

Compartilhe esta Página