paulbrodersen / matplotlib_venn_wordcloud Goto Github PK
View Code? Open in Web Editor NEWVenn diagrams with word clouds
License: MIT License
Venn diagrams with word clouds
License: MIT License
When I tried rendering this,only the word cloud is displayed.but the circles are not displayed.
Code I have tried:
fig, ax = plt.subplots(figsize=(10,10))
ax.set_title('Top 50 Cat and Dog Names in Seattle', fontsize=20)
v = venn2_wordcloud([set1, set2],
ax=ax, set_labels=["year1", "year2"])
# add color
v.get_patch_by_id('10').set_color('green')
v.get_patch_by_id('10').set_alpha(0.4)
v.get_patch_by_id('01').set_color('blue')
v.get_patch_by_id('01').set_alpha(0.4)
v.get_patch_by_id('11').set_color('purple')
v.get_patch_by_id('11').set_alpha(0.4)
html_graph = mpld3.fig_to_html(fig)
Execution of example will break when using recent versions of numpy, namely >= 1.24.
Fix illustrated here:
https://numpy.org/doc/stable/release/1.20.0-notes.html#deprecations
Currently, if the input data is degenerated, i.e., two sets are empty or all intersections are empty etc., the diagram gets messed up. It would really be good to have handling of such cases because they appear quite often in real life.
Should this be fixed in matplotlib_venn_wordcloud
or in the parent matplotlib-venn
?
This is a great representation of venn diagram analysis! I'm trying to generate a venn diagram with gene names in corresponding sets. The plot I saved in Spyder is tiny and blurry, how can I adjust the size of the plot and/or its resolution?
Hi,
I love your concept and I think it is a great tool! I'm struggling with setting minimum and maximum font sizes for the words - is there a way to set it (as in a regular wordcloud)?
Some words are not rendered in the set intersection in my simple example, depending on their frequency. Here's a Google Colab link: https://colab.research.google.com/drive/1H8qTzKh0sgC4RmGAHQbFZwxIuRfcMheb?usp=sharing
Code to reproduce:
from matplotlib_venn_wordcloud import venn2_wordcloud
words_left = {
"abc": 1,
"def": 5,
"qwe": 2,
"lorem": 1,
}
words_right = {
"qwe": 3,
"abc": 1,
"zxc": 5,
"ipsum": 1,
}
word_to_frequency={word: words_left.get(word, 0) + words_right.get(word, 0) for word in words_left.keys() | words_right.keys()}
print(word_to_frequency)
venn2_wordcloud([set(words_left), set(words_right)],
word_to_frequency=word_to_frequency,
)
The middle section should have "qwe" and "abc", both are missing.
Package versions:
Collecting matplotlib-venn-wordcloud
Downloading matplotlib_venn_wordcloud-0.2.6-py3-none-any.whl (11 kB)
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from matplotlib-venn-wordcloud) (1.25.2)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from matplotlib-venn-wordcloud) (3.7.1)
Requirement already satisfied: matplotlib-venn in /usr/local/lib/python3.10/dist-packages (from matplotlib-venn-wordcloud) (0.11.10)
Requirement already satisfied: wordcloud in /usr/local/lib/python3.10/dist-packages (from matplotlib-venn-wordcloud) (1.9.3)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (1.2.0)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (4.49.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (1.4.5)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (23.2)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (9.4.0)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (3.1.1)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib->matplotlib-venn-wordcloud) (2.8.2)
Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from matplotlib-venn->matplotlib-venn-wordcloud) (1.11.4)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib->matplotlib-venn-wordcloud) (1.16.0)
Installing collected packages: matplotlib-venn-wordcloud
Successfully installed matplotlib-venn-wordcloud-0.2.6
Hello,
I am trying to use your lib to make differential analysis for a data science project. I had to make some changes to your code because sometimes sets are empty and for the visualization, venn3_unweighted comes handy (you can check out the fork¹ if you like).
One problem I couldn't solve is that composite words (that wordcloud.WordCloud handles well) are not properly recognized, thus messing the visualization.
As you see here, the article "di" is repeated in different sets:
https://raw.githubusercontent.com/rugantio/Venn/master/images/AndreaSantiagoAntonietta_words.png
I thought that the problem was at line 402 where the main.py says
if not word_to_frequency: text = " ".join(words) wc.generate(text)
I tried to fix it but couldn't do it, can you give a look?
Thank you for your work!
¹ The code I'm using https://github.com/rugantio/matplotlib_venn_wordcloud/blob/master/matplotlib_venn_wordcloud/_main.py
I installed all the prerequisites on python3.6 and am getting the following error when trying to use the library.
matplotlib versions:
root@thehost:~# pip3 freeze | grep mat
matplotlib==2.2.2
matplotlib-venn==0.11.5
matplotlib-venn-wordcloud==0.2.1
AttributeError Traceback (most recent call last)
in ()
21
22 # create visualisation
---> 23 venn2_wordcloud(sets)
/usr/local/lib/python3.6/dist-packages/matplotlib_venn_wordcloud/_main.py in venn2_wordcloud(sets, set_labels, set_colors, set_edgecolors, alpha, ax, word_to_frequency, wordcloud_kwargs)
186 venn.get_words_by_id = _func
187
--> 188 return _venn_wordcloud(venn, ax, word_to_frequency, **wordcloud_kwargs)
189
190
/usr/local/lib/python3.6/dist-packages/matplotlib_venn_wordcloud/_main.py in _venn_wordcloud(ExtendedVennDiagram, ax, word_to_frequency, **wordcloud_kwargs)
372 img.rgba += wc.to_array() / 255.
373
--> 374 img.imshow(interpolation='bilinear')
375
376 return ExtendedVennDiagram
/usr/local/lib/python3.6/dist-packages/matplotlib_venn_wordcloud/_main.py in imshow(self, **imshow_kwargs)
435 bbox = self.ax.get_position() # in figure coordinates
436 fig = self.ax.get_figure()
--> 437 subax = fig.add_axes(bbox, axisbg=None)
438
439 # plot image
/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py in add_axes(self, *args, **kwargs)
1134
1135 # create the new axes using the axes class given
-> 1136 a = projection_class(self, rect, **kwargs)
1137
1138 self._axstack.add(key, a)
/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_base.py in init(self, fig, rect, facecolor, frameon, sharex, sharey, label, xscale, yscale, **kwargs)
537
538 if len(kwargs):
--> 539 self.update(kwargs)
540
541 if self.xaxis is not None:
/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py in update(self, props)
886 try:
887 ret = [_update_property(self, k, v)
--> 888 for k, v in props.items()]
889 finally:
890 self.eventson = store
/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py in (.0)
886 try:
887 ret = [_update_property(self, k, v)
--> 888 for k, v in props.items()]
889 finally:
890 self.eventson = store
/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py in update_property(self, k, v)
879 func = getattr(self, 'set' + k, None)
880 if not callable(func):
--> 881 raise AttributeError('Unknown property %s' % k)
882 return func(v)
883
AttributeError: Unknown property axisbg
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.