solstice~ 2022-02-24 22:41 采纳率: 0%
浏览 121
已结题

generate_from_frequencies制作词云的时候报错invalid argument


OSError                                   Traceback (most recent call last)
<ipython-input-81-601b7bf65236> in <module>
      9     for sta in range(len(station)):
     10         df = pd.read_csv(r"C:\Users\srp2021\result_for_gz{}\{}POI{}.csv".format(year[i],station[sta],year[i]),encoding="utf-8")
---> 11         cloud(only(df),station)

<ipython-input-80-f1bd0278bcb8> in cloud(count, station)
      4     # 参数分别是指定字体、背景颜色、最大的词的大小、使用给定图作为背景形状
      5     wc = WordCloud(font_path='c:\\windows\\Fonts\\simhei.ttf', background_color='white', max_words=100) #, mask=graph)
----> 6     wc.generate_from_frequencies(count)  # 根据给定词频生成词云
      7     #image_color = ImageColorGenerator(graph)
      8     plt.imshow(wc)

D:\ana\envs\tensorflow\lib\site-packages\wordcloud\wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
    499                     font, orientation=orientation)
    500                 # get size of resulting text
--> 501                 box_size = draw.textsize(word, font=transposed_font)
    502                 # find possible places using integral image:
    503                 result = occupancy.sample_position(box_size[1] + self.margin,

D:\ana\envs\tensorflow\lib\site-packages\PIL\ImageDraw.py in textsize(self, text, font, spacing, direction, features, language, stroke_width)
    567         if font is None:
    568             font = self.getfont()
--> 569         return font.getsize(text, direction, features, language, stroke_width)
    570 
    571     def multiline_textsize(

D:\ana\envs\tensorflow\lib\site-packages\PIL\ImageFont.py in getsize(self, text, *args, **kwargs)
    768 
    769     def getsize(self, text, *args, **kwargs):
--> 770         w, h = self.font.getsize(text)
    771         if self.orientation in (Image.ROTATE_90, Image.ROTATE_270):
    772             return h, w

D:\ana\envs\tensorflow\lib\site-packages\PIL\ImageFont.py in getsize(self, text, direction, features, language, stroke_width)
    428         # vertical offset is added for historical reasons
    429         # see https://github.com/python-pillow/Pillow/pull/4910#discussion_r486682929
--> 430         size, offset = self.font.getsize(text, "L", direction, features, language)
    431         return (
    432             size[0] + stroke_width * 2,

OSError: invalid argument
  • 写回答

2条回答 默认 最新

  • 关注

    你读取的csv文件格式不对吧

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月12日
  • 创建了问题 2月24日

悬赏问题

  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数
  • ¥15 ADS时域 连续相位观察方法
  • ¥15 Opencv配置出错
  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused