matplotlib:尝试绘制两个图,y轴显示不正确吗?

时间:2018-07-23 16:13:47

标签: python matplotlib

过去我使用matplotlib时,通常可以直接给出y坐标,然后将其绘制出来。但是对于这里的代码,出了点问题,而且看来我要绘制的每个点的y值都在y轴上排序。这使我的图形仅显示两条斜率几乎为1的线。

all_perplexity = ['-8.83190475666315', '-8.889099207060108','-8.937124709552606', '-8.98002866432045', '-9.02144318885002', '-9.098065513533387', '-9.121312789651386'] # top graph
all_coherences = ['0.46621592082219887', '0.4162257899346048', '0.45663240775234504', '0.44337461619336155', '0.45625082629518465', '0.4411114220029285', '0.43057866557727476'] # bottom graph

import matplotlib.pyplot as plt

x = range(10, 45, 5)
plt.figure(1)
plt.subplot(211)
plt.xlabel("Num Topics")
plt.ylabel("Coherence score")
plt.plot(x, all_coherences)

plt.subplot(212) # refers to the second graph
plt.plot(x, all_perplexity)

plt.legend(("coherence_values"), loc='best')
plt.show()

the y axis seems to get sorted then plotted

如何在这两个图中自动为y轴生成正确的范围?我只是感到困惑,因为我仍在学习matplotlib,上次我使用数字时,我能够为大多数时间生成的y值设置正确的范围(通常必须使用range命令设置x值) )

为了清楚起见,这些是一组lda主题模型的困惑度和一致性值的图。 LDA主题建模是一种无监督算法,对于本帖子,您真正需要知道的是x轴会调整该算法的参数之一,即每个模型中的主题数。我创建了从num_topic = 10到num_topics = 40的一系列lda模型。这就是x轴上的表示。

y轴根据主题的数量显示每个lda模型的困惑度(在顶部图)或一致性(在底部图)。这些只是两个数字或指标,可用于帮助评估您的lda主题模型的准确性。

0 个答案:

没有答案