当我使用 Spyder 运行代码时,出现KeyError:'Patch'
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 523, in runfile
execfile(filename, namespace)
File "C:\Users\zqh\Documents\Python Scripts\untitled1.py", line 8, in <module>
from pylab import *
File "C:\Anaconda\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Anaconda\lib\site-packages\matplotlib\pylab.py", line 265, in <module>
from matplotlib.pyplot import *
File "C:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 26, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Anaconda\lib\site-packages\matplotlib\figure.py", line 36, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "C:\Anaconda\lib\site-packages\matplotlib\axes.py", line 29, in <module>
import matplotlib.spines as mspines
File "C:\Anaconda\lib\site-packages\matplotlib\spines.py", line 17, in <module>
class Spine(mpatches.Patch):
File "C:\Anaconda\lib\site-packages\matplotlib\spines.py", line 39, in Spine
@docstring.dedent_interpd
File "C:\Anaconda\lib\site-packages\matplotlib\docstring.py", line 108, in dedent_interpd
return interpd(dedent(func))
File "C:\Anaconda\lib\site-packages\matplotlib\docstring.py", line 39, in __call__
func.__doc__ = func.__doc__ and func.__doc__ % self.params
KeyError: 'Patch'
这是我的代码:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 18 16:37:52 2013
@author: zqh
"""
# Import everything from matplotlib (numpy is accessible via 'np' alias)
from pylab import *
# Create a new figure of size 8x6 points, using 100 dots per inch
figure(figsize=(8,6), dpi=80)
# Create a new subplot from a grid of 1x1
subplot(111)
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
# Plot cosine using blue color with a continuous line of width 1 (pixels)
plot(X, C, color="blue", linewidth=1.0, linestyle="-")
# Plot sine using green color with a continuous line of width 1 (pixels)
plot(X, S, color="green", linewidth=1.0, linestyle="-")
# Set x limits
xlim(-4.0,4.0)
# Set x ticks
xticks(np.linspace(-4,4,9,endpoint=True))
# Set y limits
ylim(-1.0,1.0)
# Set y ticks
yticks(np.linspace(-1,1,5,endpoint=True))
# Save figure using 72 dots per inch
# savefig("../figures/exercice_2.png",dpi=72)
# Show result on screen
show()
当我尝试在 iPython 笔记本中运行相同的代码时,代码运行良好。我不知道为什么在使用 Spyder 时会出现此错误以及如何解决它。我可以尝试什么?