publiplots.venn

publiplots.venn(sets, labels=None, colors=None, alpha=None, ax=None, fmt='{size}', color_labels=True, orientation='horizontal')[source]

Create a Venn diagram for 2-5 sets.

This function creates true Venn diagrams that show all possible intersections using ellipses (2-5 sets supported). Each region (petal) is labeled with the size of the intersection by default; use fmt to show logic strings or percentages instead. For more than 5 sets, prefer publiplots.upsetplot().

Parameters:
  • sets (list of sets or dict) – Either a list of 2-5 sets, or a dictionary mapping labels to sets. Example: [set1, set2, set3] or {‘A’: set1, ‘B’: set2, ‘C’: set3}

  • labels (list of str, optional) – Labels for each set. If sets is a dict, labels are taken from keys. Default: [‘Set A’, ‘Set B’, ‘Set C’, …]

  • colors (list of str, str, or None, optional) – Colors for each set. Can be: - List of color names/codes for each set - String name of a publiplots palette or seaborn palette - None (uses ‘pastel’ palette)

  • alpha (float, optional) – Transparency of set regions (0=transparent, 1=opaque). When None, resolved from publiplots.rcParams["alpha"].

  • ax (Axes, optional) – Matplotlib axes object. If None, creates new figure.

  • fmt (str, default='{size}') – Format string for region labels. Can include: - {size}: number of elements in the intersection - {logic}: binary string representing the intersection - {percentage}: percentage of total elements

  • color_labels (bool, default=True) – Whether to color the set labels with the same color as the petals.

  • orientation (str, default='horizontal') – Layout for a 2-way Venn diagram. 'horizontal' places the two circles side-by-side; 'vertical' stacks them with the first set on top and the second below. Only valid for 2 sets — passing 'vertical' with 3 or more sets raises ValueError.

Returns:

The axes where the Venn diagram was drawn.

Return type:

Axes

Raises:
  • ValueError – If the number of sets is not between 2 and 5 Consider using upset plot instead.

  • TypeError – If sets is not a list of sets or dict of sets

Examples

Simple 2-way Venn diagram:

>>> set1 = {1, 2, 3, 4, 5}
>>> set2 = {4, 5, 6, 7, 8}
>>> ax = pp.venn([set1, set2], labels=['Group A', 'Group B'])

Vertical 2-way Venn (circles stacked):

>>> ax = pp.venn([set1, set2], labels=['A', 'B'], orientation='vertical')

3-way Venn with custom colors:

>>> sets_dict = {'A': set1, 'B': set2, 'C': set3}
>>> colors = ['red', 'blue', 'green']
>>> ax = pp.venn(sets_dict, colors=colors)

4-way Venn with colormap:

>>> ax = pp.venn([set1, set2, set3, set4], colors='Set1')

5-way Venn diagram with percentage labels:

>>> ax = pp.venn(
...     [set1, set2, set3, set4, set5],
...     fmt='{size} ({percentage:.1f}%)'
... )

See also

publiplots.upsetplot

UpSet plot, preferred for 6+ sets or complex intersections.