下面是我正在尝试运行的简单代码:
from matplotlib import pyplot as plt
movies=["Annie", "Ben","Casa", "Gandhi", "West"]
num_oscars=[5,11,3,8,10]
xs=[i+0.1 for i, _ in enumerate(movies)]
plt.bar(xs,num_oscars)
我收到以下错误(在pycharm中运行,Anaconda安装,python 2.7):
Traceback (most recent call last):
File "C:/Users/AlexPower/Desktop/python/myCode/ch2_new_1", line 15, in <module>
plt.bar(xs,num_oscars)
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 2692, in bar
ax = gca()
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 950, in gca
return gcf().gca(**kwargs)
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 586, in gcf
return figure()
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 535, in figure
**kwargs)
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 44, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 51, in new_figure_manager_given_figure
canvas = FigureCanvasQTAgg(figure)
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 242, in __init__
super(FigureCanvasQTAgg, self).__init__(figure=figure)
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 66, in __init__
super(FigureCanvasQTAggBase, self).__init__(figure=figure)
File "C:\Users\AlexPower\Anaconda2\lib\site-packages\matplotlib\backends\backend_qt5.py", line 243, in __init__
super(FigureCanvasQT, self).__init__(figure=figure)
AttributeError: 'figure()' is not a Qt property or a signal
我在网上搜索,确实喜欢
import os
if 'QT_API' not in os.environ and 'ETS_TOOLKIT' not in os.environ:
os.environ['QT_API'] = 'pyqt'
os.environ['ETS_TOOLKIT'] = 'qt4
它没有帮助。
好心提醒。