for topic_id,topic in enumerate(lda.components_): topword = pd.DataFrame({"word":[tf_feature_names[i] for i in topic.argsort()[:-n_top_words - 1:-1]], "componets":topic[topic.argsort()[:-n_top_words - 1:-1]]}) topword.sort_values(by = "componets").plot(kind = "barh",x = "word",y = "componets",figsize=(6,8),legend=False) plt.yticks(size=10) plt.ylabel("") plt.legend("") plt.title("Topic %d" %(topic_id+1)) plt.savefig("Topic %d.png"%(topic_id+1)) plt.show() 主要代码为: for topic_id,topic in enumerate(lda.components_): plt.savefig("Topic %d.png"%(topic_id+1))