paulbrodersen / matplotlib_venn_wordcloud

Venn diagrams with word clouds
MIT License
49 stars 12 forks source link

UserWarning: Bad circle positioning warnings.warn("Bad circle positioning") AND AttributeError: 'NoneType' object has no attribute 'get_path' #6

Closed rdius closed 4 years ago

rdius commented 4 years ago
Hello @paulbrodersen ,
`[files.zip](https://github.com/paulbrodersen/matplotlib_venn_wordcloud/files/4578804/files.zip)`

Thanks a lot for this amazing work. 

As mentioned above, i'm getting these two error, the first is the UserWarming ***UserWarning: Bad circle positioning
  warnings.warn("Bad circle positioning")*** AND the second is the  ***AttributeError: 'NoneType' object has no attribute 'get_path'***. I'm using two Dataframes, from witch i build three sets of words lists. 

I have this error when i try to increase the size of the dataframe (number of  line). In this example, df[:20] and df1[:20] work good, but  df[:100] and df1[:100] do not and raise this error.

Here is my code :
`
###here  your venn3 function
def ex2(f,f1,f2):
    venn3_wordcloud([set(f), set(f1), set(f2)],
                    set_labels=['c_value','umls','tf-idf-c_m'],alpha = 0.3)
    return

### here's my sets builder
def setbuider(f,f1):
    df = pd.read_csv(f, sep="\t|,", engine='python')
    df = df[:20] #20 works but not 100
    cv = df['terms']
    umls1 = df[df['in_umls'] == 1]
    umls1 = umls1['terms']
    ###
    df1 = pd.read_csv(f1, sep="\t|,", engine='python')
    df1 = df1[:20] #20 works but not 100
    tf = df1['terms']
    ###
    umls2 = df1[df1['in_umls'] == 1]
    umls2 = umls2['terms']
    umls = pd.concat([umls1, umls2])
    ex2(cv,umls,tf) # i call venn3 with the three sets
##calling setbuider function
setbuider(f,f1)`

In attached, a zip that contains the two dataframes.

Many thanks again!
paulbrodersen commented 4 years ago

Can you provide the full traceback for the attribute error ( not just the final message)?

rdius commented 4 years ago

Hi, here the full traceback:

/home/user/anaconda3/lib/python3.7/site-packages/matplotlib_venn/_venn3.py:117: UserWarning: Bad circle positioning warnings.warn("Bad circle positioning") Traceback (most recent call last): File "/home/user/Téléchargements/matplotlib_venn_wordcloud-master/matplotlib_venn_wordcloud/venn_wc3.py", line 64, in setbuider(f2,f3) File "/home/user/Téléchargements/matplotlib_venn_wordcloud-master/matplotlib_venn_wordcloud/venn_wc3.py", line 52, in setbuider ex2(cv,umls,tf) File "/home/user/Téléchargements/matplotlib_venn_wordcloud-master/matplotlib_venn_wordcloud/venn_wc3.py", line 16, in ex2 set_labels=['P2','umls','P3'], alpha = 0.3) File "/home/user/Téléchargements/matplotlib_venn_wordcloud-master/matplotlib_venn_wordcloud/_main.py", line 317, in venn3_wordcloud return _venn_wordcloud(venn, ax, word_to_frequency, wordcloud_kwargs) File "/home/user/Téléchargements/matplotlib_venn_wordcloud-master/matplotlib_venn_wordcloud/_main.py", line 383, in _venn_wordcloud wordcloud_kwargs) File "/home/user/Téléchargements/matplotlib_venn_wordcloud-master/matplotlib_venn_wordcloud/_main.py", line 463, in _get_wordcloud path = patch.get_path() AttributeError: 'NoneType' object has no attribute 'get_path'

Process finished with exit code 1

Thank you!

paulbrodersen commented 4 years ago

Thank you for raising the issue, that was actually really helpful.

The problem arises because 2 of the subsets are empty or near-empty.

(set(cv) & set(tf)) - set(umls)
# {'antiviral activity', 'hiv aids'}
# i.e. given sets cv, uml, tv, the subset 101 is nearly empty

set(umls) <= (set(cv) | set(tf))
# True
# i.e. given sets cv, uml, tv, the subset 010 is empty:

As a consequence, matplotlib-venn (not my code) fails to find a valid layout (warnings.warn("Bad circle positioning")). Specifically, in the layout returned, the patch corresponding to subset 101 does not exist even though the word list is non-empty. My code then chokes on the fact that it expects a patch for each non-empty subset.

I can't fully resolve your issue as the layout is not something I can control. You would have to raise the issue with the creator/maintainer of matplotlib-venn. However, I do have created a workaround of sorts, such that the missing patch no now longer raises an error but just a warning, and the figure is created (albeit without a wordcloud for the subset without a patch).

Figure_1

paulbrodersen commented 4 years ago

Uploaded the new version to PyPI.

rdius commented 4 years ago

Hi @paulbrodersen ,

Thank you so must for your help and quick reply. That's working good for me.

Thanks!

paulbrodersen commented 4 years ago

Always happy to help when I get a such a good bug report. Take care!