Skip to content

Commit 5b44065

Browse files
authored
DOC simplify plotting code in NMF LDA 20newsgroups example (scikit-learn#26727)
1 parent 309a8b6 commit 5b44065

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

examples/applications/plot_topics_extraction_with_nmf_lda.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ def plot_top_words(model, feature_names, n_top_words, title):
4646
fig, axes = plt.subplots(2, 5, figsize=(30, 15), sharex=True)
4747
axes = axes.flatten()
4848
for topic_idx, topic in enumerate(model.components_):
49-
top_features_ind = topic.argsort()[: -n_top_words - 1 : -1]
50-
top_features = [feature_names[i] for i in top_features_ind]
49+
top_features_ind = topic.argsort()[-n_top_words:]
50+
top_features = feature_names[top_features_ind]
5151
weights = topic[top_features_ind]
5252

5353
ax = axes[topic_idx]
5454
ax.barh(top_features, weights, height=0.7)
5555
ax.set_title(f"Topic {topic_idx +1}", fontdict={"fontsize": 30})
56-
ax.invert_yaxis()
5756
ax.tick_params(axis="both", which="major", labelsize=20)
5857
for i in "top right left".split():
5958
ax.spines[i].set_visible(False)

0 commit comments

Comments
 (0)