#172 Custom Venn diagram

 

The charts #170 and #171 show how to make 2 and 3 groups Venn diagrams respectively. This page aims to give a few keys to custom these graphics. The code of the 3 above examples is provided. The first shows how to custom the label of a specific group (left). The second shows how to custom the lines around each circle (center). The last shows how to apply this transformation on one group only.


# Import the library
import matplotlib.pyplot as plt
from matplotlib_venn import venn3

# Custom text labels: change the label of group A
v=venn3(subsets = (10, 8, 22, 6,9,4,2), set_labels = ('Group A', 'Group B', 'Group C'))
v.get_label_by_id('A').set_text('My Favourite group!')
plt.show()

# Line style: can be 'dashed' or 'dotted' for example
v=venn3(subsets = (10, 8, 22, 6,9,4,2), set_labels = ('Group A', 'Group B', 'Group C'))
c=venn3_circles(subsets = (10, 8, 22, 6,9,4,2), linestyle='dashed', linewidth=1, color="grey")
plt.show()

# Change one group only
v=venn3(subsets = (10, 8, 22, 6,9,4,2), set_labels = ('Group A', 'Group B', 'Group C'))
c=venn3_circles(subsets = (10, 8, 22, 6,9,4,2), linestyle='dashed', linewidth=1, color="grey")
c[0].set_lw(8.0)
c[0].set_ls('dotted')
c[0].set_color('skyblue')
plt.show()

# Color
v.get_patch_by_id('100').set_alpha(1.0)
v.get_patch_by_id('100').set_color('white')
plt.show()

  • Sponsors

  • 1 comment

    • Hello there,
      Have a good night, just to let you know a little error in your code

      In the third line (import line) you have to add venn3_circles so it will end up like this: from matplotlib_venn import venn3, venn3_circles

      Hope you can find this helpful
      Regards,

      Reply

    Leave a Reply

    Your email address will not be published.