Skip to content

[Bug]: Backend is not case-insensitive #28449

Open

Description

@liambsmith

Bug summary

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 normally
from matplotlib import pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
plt.plot([1,2,3],[1,2,3])

# This opens an empty frozen window
from matplotlib import pyplot as plt
import matplotlib
matplotlib.use('tkagg')
plt.plot([1,2,3],[1,2,3])

Actual outcome

image

Expected outcome

image

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.

Operating system

Windows

Matplotlib Version

3.9.0

Matplotlib Backend

TkAgg

Python version

No response

Jupyter version

No response

Installation

pip

Activity

  1. QuLogic commented on Jun 24, 2024

    @QuLogic
    Member

    Does this happen outside of PyCharm?

  2. liambsmith commented on Jun 25, 2024

    @liambsmith
    Author

    Does this happen outside of PyCharm?

    I have not yet tested this, but I did confirm that downgrading to matplotlib 3.8.0 fixes the issue.

  3. liambsmith commented on Jun 25, 2024

    @liambsmith
    Author

    I went through pyplot.py and noticed that this line is where problems seem to arise:

    rcParams['backend'] = rcParamsDefault['backend'] = newbackend

    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.

  4. ianthomas23 commented on Jun 26, 2024

    @ianthomas23
    Member

    @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"?

  5. tacaswell commented on Jun 26, 2024

    @tacaswell
    Member

    attn @oscargus who I think is a regular pycharm user.

  6. balavay commented on Aug 14, 2024

    @balavay

    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.

  7. ianthomas23 commented on Aug 14, 2024

    @ianthomas23
    Member

    @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.

  8. Mencarelli-Simone commented on Nov 17, 2025

    @Mencarelli-Simone

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions