【问题标题】:TclError matplotlib 1.5.0TclError matplotlib 1.5.0
【发布时间】:2016-02-02 04:52:44
【问题描述】:

使用下面的代码,会生成一个 TclError。

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

当我在终端中执行我的脚本时,我得到以下信息:

/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py:1035: UserWarning: Duplicate key in file "/Users/<username>/.matplotlib/matplotlibrc", line #2
  (fname, cnt))
objc[44479]: Class TKApplication is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[44479]: Class TKMenu is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[44479]: Class TKContentView is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[44479]: Class TKWindow is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
2016-02-01 20:45:40.991 python[44479:21064918] setCanCycle: is deprecated.  Please use setCollectionBehavior instead
2016-02-01 20:45:41.000 python[44479:21064918] setCanCycle: is deprecated.  Please use setCollectionBehavior instead
Exception in Tkinter callback
Traceback (most recent call last):
  File "/Users/<username>/anaconda/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
    return self.func(*args)
  File "/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 283, in resize
    self.show()
  File "/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 355, in draw
    tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
  File "/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 30, in blit
    id(data), colormode, id(bbox_array))
TclError

是什么导致了这个错误?我尝试将backend: TkAgg 添加到我的matplotlibrc 文件中,但无济于事。

请指教

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    想通了:

    而不是使用:

    matplotlib.use('TkAgg')
    

    使用:

    matplotlib.use('Qt4Agg')
    

    或任何其他后端

    【讨论】:

      【解决方案2】:

      您可以使用“TkAgg”,但需要安装 Tkinter 而不是 conda。 pil/pillow 和 matplotlib 的 Anaconda 软件包似乎没有正确包含 TK。使用 conda 安装 pip,然后运行 ​​pip install pillow matplotlib (Linux)

      在 Windows 上,您可以使用 gohlke 的软件包 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 使用 --force-reinstall 枕头 matplotlib 安装

      然后 Tkinter TkAgg 将工作。

      【讨论】:

        猜你喜欢
        • 2014-10-08
        • 1970-01-01
        • 1970-01-01
        • 2021-09-18
        • 2021-02-09
        • 2013-01-16
        • 1970-01-01
        • 1970-01-01
        • 2022-07-08
        相关资源
        最近更新 更多