word_cloud: Value Error: ImageColorGenerator is smaller than the canvas
Description
Hey I am definitely sure that my ImageColorGenerator is bigger than my canvas and I even tried to change the canvas width height to more and less but I am always getting this value error no matter what. Here is my code -
Example:
mask3 = np.array(Image.open(path.join(d, "test7.png")))
wc = WordCloud(background_color="white", max_words=1000, mask=mask3,stopwords=q,
max_font_size=150, random_state=42)
wc.generate(str4)
# create coloring from image
image_colors = ImageColorGenerator(mask3)
print(image_colors.image.shape)
print(wc.width, wc.height)
plt.figure(figsize=[5,5])
plt.tight_layout(pad=0)
plt.imshow(wc.recolor(color_func=image_colors), interpolation="bilinear")
plt.axis("off")
plt.show()
Explanation
This Image test7 here is 800800 and I know that default canvas is 400200 I have another image which is 900*900 and that is working perfectly.
Can you explain me as to how this is working and what is happening:
output for test7 image ( the red thing with eyes)
(800, 800, 4) 400 200
Images
This is the image with which it is working perfectly This is the image which is showing error This is the image to which I actually want to do it ultimately this image is 500*306
Please help
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 38 (21 by maintainers)
Thanks for your reports but they would have been much easier to investigate if you’d have provided a minimum reproducing example, such as the 4 lines I gave above.
fyi: if you are stilling running into this error (“ValueError: ImageColorGenerator is smaller than the canvas”) when generating the word cloud from frequencies and using small font sizes, make sure there isn’t a blank string (‘’) in your word dictionary.
e.g., running this fixed things for me:
in my case, the issue stemmed from a (0,0) box size associated with the blank string.
Data structure:
Full code
output