无法在我的程序中使用matplotlib函数 [英] Unable to use matplotlib functions in my program

查看:461
本文介绍了无法在我的程序中使用matplotlib函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 10(conda版本4.3.8)中运行Anaconda安装

I'm running an Anaconda installation in windows 10 (conda version 4.3.8)

这是我要在python命令行中运行的代码:

This is the code I'm trying to run in the python command line:

import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [5,6,7,8]
plt.figure(1)
plt.plot(x,y)

最后一行引发以下错误:

The last line throws the following error:

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:971: MatplotlibDeprecationWarning: The is_string_like function was deprecated in version 2.1.
if is_string_like(family):
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:697: MatplotlibDeprecationWarning: The is_string_like function was deprecated in version 2.1.
if is_string_like(family):
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\text.py:218: MatplotlibDeprecationWarning: The is_string_like function was deprecated in version 2.1.
elif is_string_like(fontproperties):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 3307, in plot
  ax = gca()
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 950, in gca
  return gcf().gca(**kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1368, in gca
  return self.add_subplot(1, 1, 1, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1020, in add_subplot
  a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_subplots.py", line 73, in __init__
  self._axes_class.__init__(self, fig, self.figbox, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 529, in __init__
  self._init_axis()
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 622, in _init_axis
  self.xaxis = maxis.XAxis(self)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 676, in __init__
  self.cla()
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 760, in cla
  self.reset_ticks()
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line 771, in reset_ticks
  cbook.popall(self.majorTicks)
AttributeError: module 'matplotlib.cbook' has no attribute 'popall'

我在根环境中运行此命令这也是conda list

I'm running this in the root environment Also here is part of the output of the conda list

根目录中是否存在多个版本的matplotlib?我该如何解决?

Are multiple versions of matplotlib in root causing this? How do I resolve this?

推荐答案

在尝试将matplotlib.pyplot与最新版本的matplotlib(通过Anaconda发行版进行更新)一起使用时,我遇到了一个非常相似的错误.该错误似乎是在python的根版本和Anaconda发行版之间,因为以下解决了该问题:

While attempting to use matplotlib.pyplot with the latest version of matplotlib (updated through the Anaconda distribution) I got a very similar error. The error appears to be between the root python version and the Anaconda distribution as the following solves the problem:

  • 使用pip卸载matplotlib:"pip卸载matplotlib"
  • 使用conda卸载matplotlib:"conda卸载matplotlib"
  • 使用conda安装matplotlib:"conda install matplotlib"

matplotlib的多个版本确实是问题所在.这是根据以下信息(以屏幕截图的形式提供)推断的:

Multiple versions of matplotlib does appear to be the issue. This was inferred from the following information (provided in the form of screenshots):

conda卸载matplotlib

pip卸载matplotlib

请注意两个屏幕截图中提到的matplotlib版本.希望这会有所帮助!

Note the matplotlib versions mentioned in the two screenshots. Hope this helps!

这篇关于无法在我的程序中使用matplotlib函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆