回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我对我最喜欢的节目中说的话进行了频率分析。我在做一个绘图。barh(s1e1_y,s1e1_x),但它是按单词而不是值排序的。
<code>>>> s1e1_y</code>的输出
是</p>
<pre><code>['know', 'go', 'now', 'here', 'gonna', 'can', 'them', 'think', 'come', 'time', 'got', 'elliot', 'talk', 'out', 'night', 'been', 'then', 'need', 'world', "what's"]
</code></pre>
<p>以及<code>>>>s1e1_x</code></p>
<p><code>[42, 30, 26, 25, 24, 22, 20, 19, 19, 18, 18, 18, 17, 17, 15, 15, 14, 14, 13, 13]
</code>
当实际绘制绘图时,即使绘图列表未排序,也会按字母顺序对图表的y轴刻度进行排序。。。</p>
<pre><code>s1e1_wordlist = []
s1e1_count = []
for word, count in s1e01:
if((word[:-1] in excluded_words) == False):
s1e1_wordlist.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(word[:-1])
s1e1_count.append(int(count))
s1e1_sorted = sorted(list(sorted(zip(s1e1_count, s1e1_wordlist))),
reverse=True)
s1e1_20 = []
for i in range(0,20):
s1e1_20.append(s1e1_sorted[i])
s1e1_x = []
s1e1_y = []
for count, word in s1e1_20:
s1e1_x.append(word)
s1e1_y.append(count)
plot.figure(1, figsize=(20,20))
plot.subplot(341)
plot.title('Season1 : Episode 1')
plot.tick_params(axis='y',labelsize=8)
plot.barh(s1e1_x, s1e1_y)
</code></pre>