【发布时间】:2020-12-25 01:10:46
【问题描述】:
我一直在尝试制作一个程序,该程序可以在 2 人之间的 Whatsapp 聊天期间绘制一个单词的使用频率。例如,night 这个词在几天内被使用了几次,而在大部分时间里被使用了 0 次。我的图如下
这里是代码
word_occurances = [0 for i in range(len(just_dates))]
for i in range(len(just_dates)):
for j in range(len(df_word)):
if just_dates[i].date() == word_date[j].date():
word_occurances[i] += 1
title = person2.rstrip(':') + ' with ' + person1.rstrip(':') + ' usage of the word - ' + word
plt.plot(just_dates, word_occurances, color = 'purple')
plt.gcf().autofmt_xdate()
plt.xlabel('Time')
plt.ylabel('number of times used')
plt.title(title)
plt.savefig('Graphs/Words/' + title + '.jpg', dpi = 200)
plt.show()
word_occurrances 是一个列表
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 0, 0, 1, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
我想要的是图表仅连接使用它的点,同时在 x 轴上显示整个时间线。我不希望图表触及 0。我该怎么做?我搜索并找到了类似的答案,但没有一个能像我一样工作。
【问题讨论】:
标签: python python-3.x pandas numpy matplotlib