konstantint / matplotlib-venn

Area-weighted venn-diagrams for Python/matplotlib
MIT License
495 stars 67 forks source link

Italicize the labels #58

Closed Amrithasuresh closed 3 years ago

Amrithasuresh commented 3 years ago

Thank you for the wonderful library. How to italicize the labels? Any pointers?

from matplotlib_venn import venn3
from matplotlib import pyplot as plt
import numpy as np

plt.figure(figsize=(10, 10))
v3 = venn3(subsets={'100': 30, '010': 30, '110': 17,
                     '001': 30, '101': 17, '011': 17, '111': 5},
          set_labels=('Lactobacillus brevis', 'Lactobacillus bombicola', 'Lactobacillus bambusae'))

# v3 = venn3(subsets={'100': 30, '010': 30, '110': 17,
                    '001': 30, '101': 17, '011': 17, '111': 5})

v3.get_patch_by_id('100').set_color('red')
v3.get_patch_by_id('010').set_color('yellow')
v3.get_patch_by_id('001').set_color('blue')
v3.get_patch_by_id('110').set_color('orange')
v3.get_patch_by_id('101').set_color('purple')
v3.get_patch_by_id('011').set_color('green')
v3.get_patch_by_id('111').set_color('grey')

v3.get_label_by_id('100').set_text("1,000")
v3.get_label_by_id('010').set_text("6,000")
v3.get_label_by_id('001').set_text("9,000")
v3.get_label_by_id('110').set_text("1")
v3.get_label_by_id('101').set_text("15")
v3.get_label_by_id('011').set_text("34")
v3.get_label_by_id('111').set_text("0")

for text in v3.subset_labels:
    text.set_fontsize(13)

plt.show()
konstantint commented 3 years ago

All the labels are Text objects which have a set_fontstyle method:

for text in v3.subset_labels:
    text.set_fontstyle("italic")

for text in v3.set_labels:
  text.set_fontstyle("italic")