Skip to content

Commit

Permalink
Update Blog “2020-07-12-janomeとneologdとgithub-actionを使ってtwitter-wordc…
Browse files Browse the repository at this point in the history
…loudを作ろう!”
  • Loading branch information
tubone24 committed Sep 22, 2020
1 parent d2427f0 commit 3742f9d
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,35 @@ WordCloudとはタグクラウドとも呼ばれており、出現単語を雲

## PythonでWordCloudを作るには?

PythonでWordCloudを作るには[WordCloud](https://amueller.github.io/word_cloud/index.html)というライブラリが便利です。
PythonでWordCloudを作るには[WordCloud](https://amueller.github.io/word_cloud/index.html)というライブラリが便利です。

使い方はかんたんで、

```python
words = self.__word_count()
text = " ".join(words)
if mask == "rect":
mask = None
elif mask:
mask = np.array(Image.open(mask))
else:
x, y = np.ogrid[:450, :900]
mask = ((x - 225) ** 2 / 5 ** 2) + ((y - 450) ** 2 / 10 ** 2) > 40 ** 2
mask = 255 * mask.astype(int)

if alpha:
wordcloud = WordCloud(background_color=None,
colormap="viridis",
font_path=FONT_PATH,
mode="RGBA",
mask=mask
).generate(text)
wordcloud.to_file(filename)
else:
wordcloud = WordCloud(background_color="white",
colormap="viridis",
font_path=FONT_PATH,
mask=mask
).generate(text)
wordcloud.to_file(filename)
```

0 comments on commit 3742f9d

Please sign in to comment.