Imran
Imran

Reputation: 31

Subset Venn Diagrams - i.e. venn diagrams embedded in whole set

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.

Upvotes: 1

Views: 1016

Answers (2)

KT.
KT.

Reputation: 11430

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)

Upvotes: 1

Imran
Imran

Reputation: 31

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()

Upvotes: 2

Related Questions