You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
matplotlib.use('tkagg') and matplotlib.use('TkAgg') do not do the same thing, the former freezes until show or pause is called, the latter is interactive
Code for reproduction
# This works normallyfrommatplotlibimportpyplotaspltimportmatplotlibmatplotlib.use('TkAgg')
plt.plot([1,2,3],[1,2,3])
# This opens an empty frozen windowfrommatplotlibimportpyplotaspltimportmatplotlibmatplotlib.use('tkagg')
plt.plot([1,2,3],[1,2,3])
Actual outcome
Expected outcome
Additional information
I have tested this on Windows 10 and 11 using PyCharm (223.8617.48 and also the most recent 232.10319.12). I have tested with matplotlib 3.9.0 as well as a few older versions. I have tested in multiple Python versions, including 3.11.9 and 3.9.13. It seems to work with matplotlib 3.8.3.
Specifically, if I use newbackend.lower() anywhere else it seems there is no issue unless rcParams['backend'] receives it (the default one works fine with the lowercase).
This and the above comment lead me to believe it might have something to do with the new BackendRegistry introduced in 3.9.0 as it also works when using 3.8.0, 3.8.3, and 3.8.4.
@liambsmith The BackendRegistry changes in Matplotlib 3.9.0 allow a backend name to be of any case, as whenever one is used internally in Matplotlib it is converted to lowercase first. It is still stored in rcParams with whatever case you use in matplotlib.use(...). So in pure Matplotlib all of matplotlib.use("tkagg"), matplotlib.use("TkAgg") and even matplotlib.use("tkAGG") give the same (correct) results, but a call to matplotlib.get_backend() will return the backend with the same capitalisation that was specified.
I have just checked on Windows using Python 3.11.9 and Matplotlib 3.9.0 and both of your examples work correctly for me using python, ipython and jupyter. So I think this is an issue with PyCharm. I presume they are doing their own event loop handling, so probably that is expecting "TkAgg"?
I have had the same issue in VS code so probably not a Pycharm issue (matplotlib version 3.9.1). By default the backend is 'tkagg' which causes an unresponsive window to appear but when I manually set it to TkAgg the plotting works fine. I have downgraded to matplotlib version 3.8.0 as suggested which fixes the issue.
@balavay It is the same issue. Any downstream library or IDE that attempts to use Matplotlib with its own backend handling and event loop integration needs to keep up with changes that occur here.
Downgrading Matplotlib doesn't fix the issue, it avoids the issue by remaining in the past. The only way such issues are fixed is by PyCharm, VSCode, etc keeping up with changes here. Maintainers of those projects are welcome to talk with us if they so wish; they have to fix the problem at their end either way.
I manage to solve this by installing 'jupyter' in the project venv.
Doing so, plotting in the console mode behaves correctly both with 'tkAgg' and 'Qt5Agg' backends.
I have no idea why this works.
Activity
QuLogic commentedon Jun 24, 2024
Does this happen outside of PyCharm?
liambsmith commentedon Jun 25, 2024
I have not yet tested this, but I did confirm that downgrading to matplotlib 3.8.0 fixes the issue.
liambsmith commentedon Jun 25, 2024
I went through pyplot.py and noticed that this line is where problems seem to arise:
rcParams['backend'] = rcParamsDefault['backend'] = newbackendSpecifically, if I use newbackend.lower() anywhere else it seems there is no issue unless rcParams['backend'] receives it (the default one works fine with the lowercase).
This and the above comment lead me to believe it might have something to do with the new BackendRegistry introduced in 3.9.0 as it also works when using 3.8.0, 3.8.3, and 3.8.4.
ianthomas23 commentedon Jun 26, 2024
@liambsmith The
BackendRegistrychanges in Matplotlib 3.9.0 allow a backend name to be of any case, as whenever one is used internally in Matplotlib it is converted to lowercase first. It is still stored inrcParamswith whatever case you use inmatplotlib.use(...). So in pure Matplotlib all ofmatplotlib.use("tkagg"),matplotlib.use("TkAgg")and evenmatplotlib.use("tkAGG")give the same (correct) results, but a call tomatplotlib.get_backend()will return the backend with the same capitalisation that was specified.I have just checked on Windows using Python 3.11.9 and Matplotlib 3.9.0 and both of your examples work correctly for me using
python,ipythonandjupyter. So I think this is an issue with PyCharm. I presume they are doing their own event loop handling, so probably that is expecting"TkAgg"?tacaswell commentedon Jun 26, 2024
attn @oscargus who I think is a regular pycharm user.
balavay commentedon Aug 14, 2024
I have had the same issue in VS code so probably not a Pycharm issue (matplotlib version 3.9.1). By default the backend is 'tkagg' which causes an unresponsive window to appear but when I manually set it to TkAgg the plotting works fine. I have downgraded to matplotlib version 3.8.0 as suggested which fixes the issue.
ianthomas23 commentedon Aug 14, 2024
@balavay It is the same issue. Any downstream library or IDE that attempts to use Matplotlib with its own backend handling and event loop integration needs to keep up with changes that occur here.
Downgrading Matplotlib doesn't fix the issue, it avoids the issue by remaining in the past. The only way such issues are fixed is by PyCharm, VSCode, etc keeping up with changes here. Maintainers of those projects are welcome to talk with us if they so wish; they have to fix the problem at their end either way.
Mencarelli-Simone commentedon Nov 17, 2025
I manage to solve this by installing 'jupyter' in the project venv.
Doing so, plotting in the console mode behaves correctly both with 'tkAgg' and 'Qt5Agg' backends.
I have no idea why this works.