selfteaching / selfteaching/selfteaching-python-camp
Day13 作业输出的汉字都成了方框,请问如何解决
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 151
- Forks
- 875
- PR merge metrics
- No merged PRs in 30d
Description
以下是我的代码,感觉应该是编码问题。说实话今天资料里提供的这个库我没太弄懂,代码都是照搬的。
from wxpy import *
bot = Bot()
my_friend = bot.friends()
@bot.register(my_friend,SHARING)
def auto_reply(msg):
text = msg.url
print(text)
import requests
response = requests.get(text)
# 以上通过requests请求文章链接,获取网页内容
from pyquery import PyQuery
document = PyQuery(response.text)
content = document('#js_content').text() # 将网页内容提取为一个字符串文本作为输入
print(content)
import mymodule.stats_word
try:
if not isinstance(content,str):
raise ValueError()
except ValueError:
print('输入的不是文本格式,请重新输入:')
dic = mymodule.stats_word.stats_text_cn(content) # 调用函数进行分词并统计词频
dic = dict(dic)
import matplotlib.pyplot
import numpy
# Fixing random state for reproducibility
numpy.random.seed(19680801)
matplotlib.pyplot.rcdefaults()
fig, ax = matplotlib.pyplot.subplots()
# Example data
word = []
frequency = []
for i in dic:
word.append(i)
frequency.append(dic[i])
y_pos = numpy.arange(len(word))
error = numpy.random.rand(len(word))
ax.barh(y_pos, frequency, xerr=error, align='center',
color='green', ecolor='black')
ax.set_yticks(y_pos)
ax.set_yticklabels(word)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel('词语出现次数')
ax.set_title('你刚才所发文章的词频统计')
matplotlib.pyplot.savefig('words_frequency.png')
msg.reply_image('words_frequency.png')
embed()
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the inline script around the matplotlib.pyplot plotting and savefig calls; run it and inspect words_frequency.png, focusing on the Chinese tick labels and titles. Done means the generated image displays those characters instead of square boxes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100