Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update polarity.py to return polarity_wordcloud object #5

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions juxtorpus/features/polarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _selected_dtms(self, tokeniser_func: Optional, **kwargs) -> Generator[DTM, N
return (corpus.dtm for corpus in self._jux().corpora)

def wordcloud(self, dtm_names: tuple[str, str] | str, metric: str, top: int = 50, colours=('blue', 'red'),
stopwords: list[str] = None, **kwargs):
stopwords: list[str] = None, return_wc: bool = False, **kwargs):
""" Generate a wordcloud using one of the 3 modes tf, tfidf, log_likelihood. """
polarity_wordcloud_func = self.metrics.get(metric, None)
if polarity_wordcloud_func is None:
Expand All @@ -126,8 +126,10 @@ def wordcloud(self, dtm_names: tuple[str, str] | str, metric: str, top: int = 50
height, width = 24, 24
pwc, add_legend = polarity_wordcloud_func(dtm_names, top, colours, stopwords, **kwargs)
pwc._build(resolution_scale=int(height * width * 0.005))
fig, ax = plt.subplots(figsize=(height / 2, width / 2))

if return_wc:
return pwc
fig, ax = plt.subplots(figsize=(height / 2, width / 2))
names = self._jux().corpus_0.name, self._jux().corpus_1.name
legend_elements = [Patch(facecolor=colours[0], label=names[0]), Patch(facecolor=colours[1], label=names[1])]
legend_elements.extend(add_legend)
Expand Down