当前位置:网站首页>Wordcloud colormap color set and custom colors
Wordcloud colormap color set and custom colors
2022-07-06 17:34:00 【geekqian】
Blind toss series
Cough , Shameless thief copied another blog post
Reference link :
- https://towardsdatascience.com/how-to-create-beautiful-word-clouds-in-python-cfcf85141214
- https://matplotlib.org/stable/tutorials/colors/colormaps.html
- https://blog.csdn.net/qq_34604224/article/details/121391890
- https://www.datacamp.com/community/tutorials/wordcloud-python
On the first code , By designation colormap='XXX' This property can use different color sets
# transformation
def transform_format(val):
if val == 0:
return 255
else:
return val
mask = np.array(Image.open('plugins/groupword/bg.png'))
image_colors = ImageColorGenerator(mask)
# Handle mask Invalid question
mask = mask[:,:,0]
transformed_mask = np.ndarray((mask.shape[0],mask.shape[1]), np.int32)
for i in range(len(mask)):
transformed_mask[i] = list(map(transform_format, mask[i]))
word_cloud = WordCloud(font_path="plugins/groupword/wqy-microhei.ttc",
background_color='rgba(255, 255, 255, 0)', # This determines the background color
mode='RGBA',
colormap='Spectral', # Color set
#mask=transformed_mask,
#color_func = image_colors, # Determine the text color , Take the color of the corresponding position of the picture where the text is covered .
#contour_width = 3, # Border width
#width=800, # Specify the length , Unit pixel , Appoint mask The post attribute does not take effect
#height=800,
#max_font_size=150, # Set font maximum
#random_state=30, # Set how many randomly generated states there are , That's how many color schemes there are
#max_words=2000, # Sets the maximum number of words to be displayed
collocations=True, # Remove repeated words after opening
).generate_from_frequencies(words)
Custom color
Custom color requirements , It should be possible to achieve : Specify a picture that contains only the colors you want to customize , use ImageColorGenerator Extract the color , Set to wordcloud, Don't use it here colormap , use color_func This parameter
from wordcloud import WordCloud,ImageColorGenerator
mask = np.array(Image.open('plugins/groupword/bg.png'))
image_colors = ImageColorGenerator(mask) # Extract colors from pictures

colormap Color set ( Reference link 2)
- Sequential
['viridis', 'plasma', 'inferno', 'magma', 'cividis']

['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']

- Sequential2
['binary', 'gist_yarg', 'gist_gray', 'gray', 'bone',
'pink', 'spring', 'summer', 'autumn', 'winter', 'cool',
'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper']

- Diverging
['PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 'RdYlBu',
'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']

- Cyclic
['twilight', 'twilight_shifted', 'hsv']

- Qualitative
['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2',
'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b',
'tab20c']

- Miscellaneous
['flag', 'prism', 'ocean', 'gist_earth', 'terrain',
'gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap',
'cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet',
'turbo', 'nipy_spectral', 'gist_ncar']

边栏推荐
- 轻量级计划服务工具研发与实践
- The problem of "syntax error" when uipath executes insert statement is solved
- List set data removal (list.sublist.clear)
- Flink parsing (IV): recovery mechanism
- EasyRE WriteUp
- mysql的合计/统计函数
- 02个人研发的产品及推广-短信平台
- Brush questions during summer vacation, ouch ouch
- [reverse] repair IAT and close ASLR after shelling
- Programmer orientation problem solving methodology
猜你喜欢

轻量级计划服务工具研发与实践

Flink源码解读(二):JobGraph源码解读

Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘

学习投资大师的智慧

全网最全tcpdump和Wireshark抓包实践

Models used in data warehouse modeling and layered introduction

案例:检查空字段【注解+反射+自定义异常】

Akamai talking about risk control principles and Solutions

pip install pyodbc : ERROR: Command errored out with exit status 1

Shawshank's sense of redemption
随机推荐
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
Flink parsing (IV): recovery mechanism
pip install pyodbc : ERROR: Command errored out with exit status 1
TCP连接不止用TCP协议沟通
基于Infragistics.Document.Excel导出表格的类
C#版Selenium操作Chrome全屏模式显示(F11)
JVM garbage collection overview
04 products and promotion developed by individuals - data push tool
Connect to LAN MySQL
【逆向中级】跃跃欲试
Serial serialold parnew of JVM garbage collector
03个人研发的产品及推广-计划服务配置器V3.0
Interpretation of Flink source code (III): Interpretation of executiongraph source code
Program counter of JVM runtime data area
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
Flink parsing (VII): time window
JVM 垃圾回收器之Garbage First
ByteDance overseas technical team won the championship again: HD video coding has won the first place in 17 items
Selenium test of automatic answer runs directly in the browser, just like real users.
Learn the wisdom of investment Masters