質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

6361閲覧

pythonでのwordcloudをカラフルにしたいです

nyumonsya

総合スコア34

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/01/16 03:35

編集2019/01/16 03:39

pythonでwordcloudを作成しているのですが、ネットで見る画像に比べ、配色がとても地味です。
パラメータを見ても分からなかったので・・、カラフルな配色にする方法があればご教示頂きたいです。
よろしくお願いします!
↓↓今回作成した画像
作成ファイル
↓↓今回使用のソースコード

# coding: utf-8 #!/usr/bin/env python from wordcloud import WordCloud from PIL import Image import numpy as np import re from collections import Counter import MeCab import itertools from igraph import * #文字色を設定①〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓 #def color_func(word, font_size, position, orientation, random_state, font_path): # return 'pink' #文字色を設定②〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓 def recolor(self, random_state=None, color_func=None, colormap=None): if isinstance(random_state, int): random_state = Random(random_state) self._check_generated() if color_func is None: if colormap is None: color_func = self.color_func else: color_func = colormap_color_func(colormap) self.layout_ = [(word_freq, font_size, position, orientation, color_func(word=word_freq[0], font_size=font_size, position=position, orientation=orientation, random_state=random_state, font_path=self.font_path)) for word_freq, font_size, position, orientation, _ in self.layout_] return self #テキストを設定〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓 with open("C:/python/abe.txt") as f: string = f.read() wordcloud = WordCloud( background_color="white", #color_func = color_func, font_path="C:/python/AozoraMinchoHeavy.ttf", #mask=girl_mask, width=800, height=600 ).generate(string) wordcloud.to_file("./wordcloud_image_abe.png")

↓↓参考用:ネットの画像
参考用:ネットの画像

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

colormap でカラーマップを変更されてはどうでしょうか?

選択できるカラーマップ名の一覧

matplotlib - カラーマップについて

python

1# coding: utf-8 2from wordcloud import WordCloud 3 4text = "Chief Justice Roberts, President Carter, President Clinton, President \ 5 Bush, President Obama, fellow Americans, and people of the world: \ 6 thank you. We, the citizens of America, are now joined in a great \ 7 national effort to rebuild our country and to restore its promise for \ 8 all of our people. \ 9 Together, we will determine the course of America and the world for \ 10 years to come. \ 11 We will face challenges. We will confront hardships. But we will get \ 12 the job done. \ 13 Every four years, we gather on these steps to carry out the orderly \ 14 and peaceful transfer of power, and we are grateful to President Obama \ 15 and First Lady Michelle Obama for their gracious aid throughout this \ 16 transition. They have been magnificent." 17 18wordcloud = WordCloud( 19 background_color="white", width=800, height=600, colormap='prism').generate(text) 20 21wordcloud.to_file("wordcloud_sample.png")

イメージ説明

投稿2019/01/16 09:51

tiitoi

総合スコア21954

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nyumonsya

2019/01/16 10:01

tiitoiさん colormapの調整で、即出来ました!! 誠にありがとうございました!! とても助かりましたm(_ _)m
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問