Python测试由于TCL误差而在Matplotlib子图上随机失败

发布于 2025-02-05 20:52:00 字数 2699 浏览 2 评论 0原文

由于TCL错误,我在plt.subplots上失败了测试。这是测试,并在上升错误的行中:

    def test_plot_epoch_segmentation():
        """Test segmentation plots for epochs."""
        n_clusters = 4
        labels = np.random.choice(
            [-1, 0, 1, 2, 3], (len(epochs), epochs.times.size)
        )
    
        plot_epoch_segmentation(labels, epochs, n_clusters)
        plt.close("all")
    
        # provide ax
        f, ax = plt.subplots(1, 1)
        plot_epoch_segmentation(labels, epochs, n_clusters, axes=ax)
        plt.close("all")
    
        # provide cbar_ax
>>      f, cbar_ax = plt.subplots(1, 1)

请注意,上面的4行...相似的plt.subplots被调用,并且不会升高。毫无疑问,这是提出的错误:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py:1455: in subplots
    fig = figure(**fig_kw)
C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py:808: in figure
C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py:949: in new_figure_manager_given_figure
    window = tk.Tk(className="matplotlib")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tkinter.Tk object .>, screenName = None, baseName = 'pytest'
className = 'matplotlib', useTk = True, sync = False, use = None

    def __init__(self, screenName=None, baseName=None, className='Tk',
                 useTk=True, sync=False, use=None):
        """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
        be created. BASENAME will be used for the identification of the profile file (see
        readprofile).
        It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
        is the name of the widget class."""
        self.master = None
        self.children = {}
        self._tkloaded = False
        # to avoid recursions in the getattr code in case of failure, we
        # ensure that self.tk is always _something_.
        self.tk = None
        if baseName is None:
            import os
            baseName = os.path.basename(sys.argv[0])
            baseName, ext = os.path.splitext(baseName)
            if ext not in ('.py', '.pyc'):
                baseName = baseName + ext
        interactive = False
>       self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
E       _tkinter.TclError: invalid command name "tcl_findLibrary"

C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\tkinter\__init__.py:2270: TclError

如果有人有想法。.任何帮助将不胜感激!

I have a test failing on a plt.subplots call because of a Tcl error.. and I can't figure out why or how to fix it. Here is the test, with the line on which the error is raised:

    def test_plot_epoch_segmentation():
        """Test segmentation plots for epochs."""
        n_clusters = 4
        labels = np.random.choice(
            [-1, 0, 1, 2, 3], (len(epochs), epochs.times.size)
        )
    
        plot_epoch_segmentation(labels, epochs, n_clusters)
        plt.close("all")
    
        # provide ax
        f, ax = plt.subplots(1, 1)
        plot_epoch_segmentation(labels, epochs, n_clusters, axes=ax)
        plt.close("all")
    
        # provide cbar_ax
>>      f, cbar_ax = plt.subplots(1, 1)

Note that 4 lines above... a similar plt.subplots is called and does not raise. Without further due, here is the error raised:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py:1455: in subplots
    fig = figure(**fig_kw)
C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py:808: in figure
C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py:949: in new_figure_manager_given_figure
    window = tk.Tk(className="matplotlib")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tkinter.Tk object .>, screenName = None, baseName = 'pytest'
className = 'matplotlib', useTk = True, sync = False, use = None

    def __init__(self, screenName=None, baseName=None, className='Tk',
                 useTk=True, sync=False, use=None):
        """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
        be created. BASENAME will be used for the identification of the profile file (see
        readprofile).
        It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
        is the name of the widget class."""
        self.master = None
        self.children = {}
        self._tkloaded = False
        # to avoid recursions in the getattr code in case of failure, we
        # ensure that self.tk is always _something_.
        self.tk = None
        if baseName is None:
            import os
            baseName = os.path.basename(sys.argv[0])
            baseName, ext = os.path.splitext(baseName)
            if ext not in ('.py', '.pyc'):
                baseName = baseName + ext
        interactive = False
>       self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
E       _tkinter.TclError: invalid command name "tcl_findLibrary"

C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\tkinter\__init__.py:2270: TclError

If anyone has an idea.. any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文