python3.6使用matplotlib库遇到的问题

1.安装matplotlib遇到的问题

Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
    import _tkinter
ImportError: No module named '_tkinter'

解决方法:

sudo apt-get install python3.6-tk

2.调用matplotlib时遇到的警告

 UserWarning: 
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

The backend was *originally* set to 'TkAgg' by the following code:
  File "/home/Jade/图片/paddle_learning/Housing_forecast.py", line 15, in <module>
    import matplotlib.pyplot as plt
  File "/home/Jade/.virtualenvs/py36env/lib/python3.6/site-packages/matplotlib/pyplot.py", line 71, in <module>
    from matplotlib.backends import pylab_setup
  File "/home/Jade/.virtualenvs/py36env/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 17, in <module>
    line for line in traceback.format_stack()


  matplotlib.use('Agg')

有人建议在pyplot之前加入matplotlib.use(‘Agg’)即

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

但是这样就不弹出绘制的图了 百般搜索也未能解决,只好先恢复原样,好在是个警告先这样吧。。。。。

发布了23 篇原创文章 · 获赞 25 · 访问量 864

猜你喜欢

转载自blog.csdn.net/qq_42878057/article/details/105197408