首页 > 解决方案 > Matplotlib 返回:AttributeError:'property' 对象没有属性'__name__'

问题描述

我在 python (Jupyter) 中构建了一个 webscraper 来从博客中提取帖子内容,我想使用 csv 文件来创建一个 wordcloud。这是我正在使用的 wordcloud 代码:

%matplotlib notebook
from os import path
import matplotlib.pyplot as plt
import random

from wordcloud import WordCloud, STOPWORDS

# Open and read blog_stuff csv file
file = open("blog_stuff.csv",'r')
text = file.read()
file.close()

# Generate WordCloud 
# !!!make sure the path for the font is correct!!!
wordcloud = WordCloud(font_path='C:/Windows/Fonts/Calibri.ttf', relative_scaling = 0.25 ).generate(text)

# Save image
plt.savefig('wordcloud.png')

# Display Image
plt.show()

在我遵循的所有教程中,我一直遇到属性错误。这是错误:

----> 1 get_ipython().run_line_magic('matplotlib', 'notebook') 2 from os import path 3 import matplotlib.pyplot as plt 4 import random 5

~\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth) 2305 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals 2306 with self.builtin_trap: -> 2307 结果 = fn(args, *kwargs) 2308 返回结果 2309

在 matplotlib(自我,线)

~\Anaconda3\lib\site-packages\IPython\core\magic.py in (f, a, *k) 185 # 但对于那一点状态来说它是矫枉过正的。186 def magic_deco(arg): --> 187 call = lambda f, a, *k: f(a, *k) 188 189 if callable(arg):

~\Anaconda3\lib\site-packages\IPython\core\magics\pylab.py in matplotlib(self, line) 97 print("Available matplotlib backends: %s" % backends_list) 98 else: ---> 99 gui,后端= self.shell.enable_matplotlib(args.gui)100 self._show_matplotlib_backend(args.gui,后端)101

~\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in enable_matplotlib(self, gui) 3382 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select) 3383 -> 3384 pt.activate_matplotlib(backend) 3385 pt. configure_inline_support(自我,后端)3386

~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in activate_matplotlib(backend) 311 matplotlib.rcParams['backend'] = backend 312 --> 313 import matplotlib.pyplot 314 matplotlib.pyplot.switch_backend(backend ) 315

~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in 30 from cycler import cycler 31 import matplotlib ---> 32 import matplotlib.colorbar 33 import matplotlib.image 34 from matplotlib import rcsetup, style

~\Anaconda3\lib\site-packages\matplotlib\colorbar.py in 25 26 import matplotlib as mpl ---> 27 import matplotlib.artist as martist 28 import matplotlib.cbook as cbook 29 import matplotlib.collections as collections

~\Anaconda3\lib\site-packages\matplotlib\artist.py in 55 56 ---> 57 class Artist(object): 58 """ 59 渲染成 FigureCanvas 的对象的抽象基类。

~\Anaconda3\lib\site-packages\matplotlib\artist.py in Artist() 62 """ 63 @cbook.deprecated("3.1") ---> 64 @property 65 def aname(self): 66 return '艺术家'

~\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py in deprecate(obj, message, name, alternative, pending, addendum) 180 pass 181 """ --> 182 183 def deprecate(obj, message=消息,名称=名称,替代=替代,184 待处理=待处理,obj_type=obj_type,附录=附录):

AttributeError:“属性”对象没有属性“名称”

标签: pythonmatplotlibweb-scrapingattributesword-cloud

解决方案


推荐阅读