丹佛斯阿胶 发表于 2020-11-16 20:03

求助!用了matplotlib之后总报错

代码
import json
import requests
import wordcloud
import matplotlib
url = 'https://api.yimian.xyz/coro'
city_dict = {}
data = requests.get(url).text
json_data = json.loads(data)
for p in json_data:
    if 'cities' in p:
      for c in p['cities']:
            city_name = c['cityName']
            ccount = c['confirmedCount']
            sCount = c['suspectedCount']
            total = int(ccount) + int(sCount)
            city_dict = total
    else:
      city_name = p['provinceName']
      ccount = p['confirmedCount']
      sCount = p['suspectedCount']
      total = int(ccount) + int(sCount)
      city_dict = total
with open('city.txt', 'w')as f:
    for k, v in city_dict.items():
      f.write(f'{k}:{v}\n')
ccloud = wordcloud.WordCloud(font_path='\Windows\Fonts\msyh.ttf')
ccloud.generate_from_frequencies(frequencies=city_dict)
matplotlib.figure()
matplotlib.imshow(ccloud, interpolation='bilinear')
matplotlib.axis('off')
matplotlib.show()


报错

doctrinist 发表于 2020-11-17 09:36

matplotlib不是类,from matplotlib import pyplot调用
页: [1]
查看完整版本: 求助!用了matplotlib之后总报错