在 wordcloud+matplotlib 图像中提高图像质量

问题描述 投票:0回答:0

我有一个用 Python 使用 WordCloud 和 Matplotlib 包创建的 wordcloud,但我无法下载它的高质量图像。 如果我放大一点,我无法理解任何小词。如果我 zooz,我希望能够理解所有的单词,否则我想删除它们。

如何提高图像质量?我试着这样做增加 dpi,增加原始图像的大小并将图像类型更改为 pdf。我认为低质量来自我的 wordcloud 而不是来自 Matplotlib。

这是我的形象:

如果我放大一点,这就是我发现的:

这是我的代码:

import pandas as pd
from PIL import Image
import numpy as np
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from collections import Counter


df=pd.read_csv('word_freq_counter.csv')

word_freq_counter = Counter(dict(zip(df['Item'], df['Count'])))


mask = np.array(Image.open('fnatic_2.png'))

fig, ax = plt.subplots()

wc = WordCloud(

    relative_scaling=0.3,
    repeat=True,
    colormap='Oranges',
    font_path='C:/Windows/Fonts/seguiemj.ttf',
    mask=mask, background_color="grey",
    max_words=2000, max_font_size=256,
    min_font_size=3,
    random_state=42, width=mask.shape[1],
    height=mask.shape[0])
wc.generate_from_frequencies(word_freq_counter)

plt.imshow(wc, interpolation="bilinear")


fig.set_facecolor('gray')

ax.set_title('Fnatic\'s last week in Twitter', fontdict={'fontsize': 15},
             loc='left', pad=20, color='black')

plt.axis('off')
plt.savefig("result.png",dpi=300)
plt.show()
python matplotlib word-cloud
© www.soinside.com 2019 - 2024. All rights reserved.