teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

修正

2018/09/19 17:44

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -6,6 +6,8 @@
6
6
  * to_file(): ファイルに保存する。
7
7
  * to_array(): 形状が (Height, Width, 3) の numpy 配列として取得する。
8
8
 
9
+ font_path はフォント名でもよいみたいです。
10
+
9
11
  ```python
10
12
  import numpy as np
11
13
  from wordcloud import WordCloud

1

追記

2018/09/19 17:44

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -1,5 +1,5 @@
1
1
  matplotlib の imshow() で表示する場合、画像は描画領域の大きさに合わせてリサイズされますので、原寸大で表示したい場合は向いていません。
2
- (うまく dpi を計算すれば、表示できないこともないですが、少し面倒です。)
2
+ (うまく dpi を計算すれば、原寸大で表示できないこともないですが、少し面倒です。)
3
3
 
4
4
  WordCloud クラスに以下のメソッドがありますので、原寸大で表示してみて、それでも質問者さんの基準でぼやけているか確認してみてください。
5
5
 
@@ -30,4 +30,30 @@
30
30
  ![イメージ説明](8f1953df4424d0e0001067e2ae6b98fe.png)
31
31
 
32
32
 
33
- [wordcloud の API リファレンス](http://amueller.github.io/word_cloud/index.html)
33
+ [wordcloud の API リファレンス](http://amueller.github.io/word_cloud/index.html)
34
+
35
+ ## ウィンドウに表示したい場合
36
+
37
+ ```
38
+ import cv2
39
+
40
+ cv2.namedWindow('word cloud', cv2.WINDOW_NORMAL)
41
+ cv2.imshow('word cloud', img)
42
+ cv2.waitKey(0)
43
+ cv2.destroyAllWindows()
44
+ ```
45
+
46
+ ## IPython Notebook に表示したい場合
47
+
48
+ ```python
49
+ import IPython.display
50
+ from io import BytesIO
51
+ from PIL import Image
52
+
53
+ def show_array(img):
54
+ stream = BytesIO()
55
+ Image.fromarray(img).save(stream, 'png')
56
+ IPython.display.display(IPython.display.Image(data=stream.getvalue()))
57
+
58
+ show_array(img)
59
+ ```