1

I'm comparing a set of tweets about a new fine implemented in London that is applied to heavily polluting vehicles. I want to compare how many tweets mention words related to traffic, and how many mention words related to pollution.

I'm using a venn diagram to do this, but ideally I'd like the overlapping circles to both be contained within a large circle representing the entire set of all tweets.

Here's an example of something I mean (sorry don;t have the reputation to post images yet)

(https://media1.britannica.com/eb-media/79/63279-004-ED30922B.gif)

I'm using matplotlib-venn currently.

many thanks.

Imran
  • 31
  • 4
  • Welcome to SO! can you show us some code you've started applying to this problem? Not all good questions need accompanying code but it will helps focus the responders. see https://stackoverflow.com/help/how-to-ask – navicore Dec 27 '17 at 02:34
  • 1
    @navicore hey i managed to sort it out - see my answer below - thank you! – Imran Dec 27 '17 at 02:58

2 Answers2

2

Ah, so all you need to do is set the value of any sections outside the whole set to 0. See this code here adapted from the documentation example:

my_sets =(0,0,0,4,5,6,7)
my_labels = ["Traffic","Pollution","All Tweets"]

plt.figure(figsize=(4,4))
v = venn3(subsets= my_sets, set_labels = my_labels)
c = venn3_circles(subsets= my_sets, linestyle='dashed')
plt.show()
Imran
  • 31
  • 4
1

One possibility is to manually add a new circle around the whole diagram (assuming it does not have to have any specific precise measures, but just act as a rough indicator of the universe). For example:

from matplotlib_venn import venn3
from matplotlib import pyplot as plt
venn3((1,2,3,4,5,6,7))

from matplotlib.patches import Circle
plt.gca().add_patch(Circle([0,0], 1, fill=False, ec='k'))
plt.xlim(-1.05,1.05)
plt.ylim(-1.05,1.05)
plt.text(0.8, 0.8, 'Universe', fontsize=20)
KT.
  • 10,815
  • 4
  • 47
  • 71