قطعه کد زیر را در نظر بگیرید:
from wordcloud_fa import WordCloudFa import numpy as np from PIL import Image import matplotlib.pyplot as plt mask_array = np.array(Image.open(r"d:/word_cloud/h.jpg")) with open(r"d:/word_cloud/persian0.txt", 'r',encoding="utf8") as file: text = file.read() text = text.strip() #Remove Spaces wodcloud = WordCloudFa(mask=mask_array,background_color="white",width=1200, height=800, contour_width=3, contour_color='steelblue' ) wc = wodcloud.generate(text) image = wc.to_image() image.show() image.save(r"d:/word_cloud/p7.png") # show plt.imshow(wc, interpolation='bilinear') plt.axis("off") plt.figure() plt.imshow(mask_array, cmap=plt.cm.gray, interpolation='bilinear') plt.axis("off") plt.show()
خروجی عبارتست از: