【日本語文章の表示サンプルあり】Pythonのワードクラウドで使えるカラーマップ一覧✰ matplotlib/WordCloud✰
Pythonのワードクラウドで使えるカラーマップ一覧
PythonのWordCloudパッケージでは”matplotlib”にあるカラーマップが使用できます。
ここでは実際にワードクラウドを使ったときの全種類のカラーマップ表示例一覧をご紹介します。
WordCloudウドでのカラーマップ指定例
wordcloud = WordCloud(background_color=bg_color, colormap=”ここでカラーマップを指定”, font_path="./ipag.ttf",width=300,height=200).generate(sample_text)
zipで欲しい人はこちらから
sample.zip - Google ドライブ
5.3MB
日本語文章での表示サンプル
白背景
inferno
magma
plasma
viridis
Blues
BuGn
BuPu
GnBu
Greens
Greys
OrRd
Oranges
PuBu
PuBuGn
PuRd
Purples
RdPu
Reds
YlGn
YlGnBu
YlOrBr
YlOrRd
binary
gist_yarg
gist_gray
gray
bone
pink
spring
summer
autumn
winter
cool
Wistia
hot
afmhot
gist_heat
copper
PiYG
PRGn
BrBG
PuOr
RdGy
RdBu
RdYlBu
RdYlGn
Spectral
coolwarm
bwr
seismic
Pastel1
Pastel2
Paired
Accent
Dark2
Set1
Set2
Set3
tab10
tab20
tab20b
tab20c
flag
prism
ocean
gist_earth
terrain
gist_stern
gnuplot
gnuplot2
CMRmap
cubehelix
brg
hsv
gist_rainbow
rainbow
jet
nipy_spectral
gist_ncar
黒背景
inferno
magma
plasma
viridis
Blues
BuGn
BuPu
GnBu
Greens
Greys
OrRd
Oranges
PuBu
PuBuGn
PuRd
Purples
RdPu
Reds
YlGn
YlGnBu
YlOrBr
YlOrRd
binary
gist_yarg
gist_gray
gray
bone
pink
spring
summer
autumn
winter
cool
Wistia
hot
afmhot
gist_heat
copper
PiYG
PRGn
BrBG
PuOr
RdGy
RdBu
RdYlBu
RdYlGn
Spectral
coolwarm
bwr
seismic
Pastel1
Pastel2
Paired
Accent
Dark2
Set1
Set2
Set3
tab10
tab20
tab20b
tab20c
flag
prism
ocean
gist_earth
terrain
gist_stern
gnuplot
gnuplot2
CMRmap
cubehelix
brg
hsv
gist_rainbow
rainbow
jet
nipy_spectral
gist_ncar
zipで欲しい人はこちらから
sample.zip - Google ドライブ
5.3MB
生成コードのサンプル
wordcloudなどのインストール
pip install wordcloud
pip install matplotlib
pip install numpy
pip3 install pillow
生成コード
from IPython.display import Image, display_png from wordcloud import WordCloud background_color_list=["white","black"] color_map_list=[ 'inferno', 'magma', 'plasma', 'viridis', 'Blues', 'BuGn', 'BuPu', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink', 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper', 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic', 'Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b', 'tab20c', 'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv', 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'] sample_text="吾輩は猫である。名前はまだ無い。どこで生まれたか頓と見當がつかぬ。何ても暗薄いじめじめした所でニャー/\泣いて居た事丈は記憶して居る。吾輩はこゝで始めて人間といふものを見た。然もあとで聞くとそれは書生といふ人間で一番獰惡な種族であつたさうだ。此書生といふのは時々我々を捕へて煮て食ふといふ話である。然し其當時は何といふ考もなかつたから別段恐しいとも思はなかつた。但彼の掌に載せられてスーと持ち上げられた時何だかフハフハした感じが有つた許りである。掌の上で少し落ち付いて書生の顏を見たが所謂人間といふものゝ見始であらう。此の時妙なものだと思つた感じが今でも殘つて居る。第一毛を以て裝飾されべき筈の顏がつる/\して丸で藥罐だ。其後猫にも大分逢つたがこんな片輪には一度も出會はした事がない。加之顏の眞中が餘りに突起して居る。そうして其穴の中から時々ぷう/\と烟を吹く。どうも咽せぽくて實に弱つた。是が人間の飮む烟草といふものである事は漸く此頃知つた。" for bg_color in background_color_list: for color_map in color_map_list: wordcloud = WordCloud(background_color=bg_color, colormap=color_map, font_path="./ipag.ttf", width=300,height=200).generate(sample_text) img_file_name="./sample/"+str(bg_color)+"_"+str(color_map)+".png" wordcloud.to_file(img_file_name) print(str(color_map)) display_png(Image(img_file_name))
使用フォント
ipag.ttf
実行ファイルと同じディレクトリに配置。
トラブルシューティング
実行ファイルの名前に「wordcloud.py」と名付けてはいけない。