Repository: amueller/word_cloud

Issue:
generate_from_frequencies() raise ZeroDivisionError when there're more than one zero in the data
#### Description
Similar Issue: [Issue 308](https://github.com/amueller/word_cloud/issues/308)

At line 464 in wordcloud.py:
```
if rs != 0:
                font_size = int(round((rs * (freq / float(last_freq))
                                       + (1 - rs)) * font_size))
```

If last_freq == 0 (more than one zero in the data), ZeroDivisionError will be raised.

And I'm using generate_from_frequencies() for plotting not only frequency data, but other statistics, such as p-values, chi-square, etc. Decimals are fine, too many zeros would raise the error. I haven't tested negative values (in some cases negative values do make sense, for example in statistics), so I'm not sure whether using negative values as input data will cause any other problems. 

The workaround I'm using now is to manually remove all zeros in my data (and negative values too, I suppose), but there might be not enough words in the figure. Another workaround is to replace all zeros with a very small number, for example 0.0000000001, which produces better results.

Thanks in advance.

#### Steps/Code to Reproduce

Example:
```
import wordcloud

word_cloud = wordcloud.WordCloud()

word_cloud.generate_from_frequencies({'test': 1, 'test1': 0, 'test2': 2}) # OK
word_cloud.generate_from_frequencies({'test': 1, 'test1': 0, 'test2': 0}) # Error
```

#### Versions
Windows-10-10.0.17134-SP0
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)]
matplotlib 3.0.2
wordcoud 1.5.0

Discussion:

Patch:
diff --git a/wordcloud/wordcloud.py b/wordcloud/wordcloud.py
index b42961a..c2b9d98 100644
--- a/wordcloud/wordcloud.py
+++ b/wordcloud/wordcloud.py
@@ -466,6 +466,8 @@ class WordCloud(object):
 
         # start drawing grey image
         for word, freq in frequencies:
+            if freq == 0:
+                continue
             # select the font size
             rs = self.relative_scaling
             if rs != 0:


Test patch:
diff --git a/test/test_wordcloud.py b/test/test_wordcloud.py
index a111562..88bbadd 100644
--- a/test/test_wordcloud.py
+++ b/test/test_wordcloud.py
@@ -387,3 +387,12 @@ def test_repeat():
     frequencies = [w[0][1] for w in wc.layout_]
     # check that frequencies are sorted
     assert np.all(np.diff(frequencies) <= 0)
+
+
+def test_zero_frequencies():
+
+    word_cloud = WordCloud()
+
+    word_cloud.generate_from_frequencies({'test': 1, 'test1': 0, 'test2': 0})
+    assert len(word_cloud.layout_) == 1
+    assert word_cloud.layout_[0][0][0] == 'test'