VennDiagram
|
Create an area-equal Venn diagram visualising the relationships between two or more sets. |
|
Instantiate the set diagram from a list of sets, rather than subset sizes. |
|
Generate a set diagram with word clouds displaying the subset items. |
- class matplotlib_set_diagrams.VennDiagram(subset_sizes: ~typing.Mapping[~typing.Tuple[bool], int | float], subset_labels: ~typing.Mapping[~typing.Tuple[bool], str] | None = None, subset_label_formatter: ~typing.Callable[[~typing.Tuple[bool], int | float], str] = <function VennDiagram.<lambda>>, set_labels: list[str] | None = None, set_colors: list[tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]] | None = None, ax: ~matplotlib.axes._axes.Axes | None = None)[source]
Create an area-equal Venn diagram visualising the relationships between two or more sets.
Sets are represented through overlapping circles. The size of a subset is indicated by the label of the corresponding patch; the size of the patch, however, is not indicative of the size of the subset, such that even zero-size subsets can be represented.
- Parameters:
- subset_sizesMapping[Tuple[bool], int | float]
The dictionary mapping each subset to its size. Subsets are represented by tuples of booleans using the inclusion/exclusion nomenclature, i.e. each entry in the tuple indicates if the corresponding set is a superset of the subset. For example, given the sets A, B, C, the subset (1, 1, 1) corresponds to the intersection of all three sets, whereas (1, 1, 0) is the subset formed by the difference between the intersection of A with B, and C.
- subset_labelsOptional[Mapping[Tuple[bool], str]]
A dictionary mapping each subset to its desired label. If None, the subset_label_formatter is used create subset labels based on the subset sizes.
- subset_label_formatterCallable[[Tuple[bool], int | float], str]
The formatter used to create subset labels based on the subset sizes. The argument is ignored if subset_labels are not None.
- set_labelsOptional[list[str]]
A list of set labels. If none, defaults to the letters of the alphabet (capitalized).
- set_colorsOptional[list[ColorType]]
A corresponding list of matplotlib colors. If none, defaults to the default matplotlib color cycle.
- axOptional[plt.Axes]
The matplotlib axis instance to draw onto. If none provided, a new figure with a single axis is instantiated.
- Attributes:
- subset_areasMapping[Tuple[bool], int | float]
The dictionary mapping each subset to a desired area size.
- originsNDArray
The circle origins.
- radiiNDArray
The circle radii.
- subset_geometriesdict[Tuple[bool], shapely.geometry.polygon.Polygon]
The dictionary mapping each subset to its shapely geometry.
- subset_artistsdict[tuple[bool], plt.Polygon]
The matplotlib Polygon patches representing each subset.
- subset_label_artistsdict[tuple[bool], plt.Text]
The matplotlib text objects used to label each subset.
- set_label_artistslist[plt.Text]
The matplotlib text objects used to label each set.
- axplt.Axes
The matplotlib axis instance.
- classmethod VennDiagram.from_sets(sets, *args, **kwargs)
Instantiate the set diagram from a list of sets, rather than subset sizes.
- Parameters:
- setslist[set]
The sets.
- subset_labelsOptional[Mapping[Tuple[bool], str]]
A dictionary mapping each subset to its desired label or None. If None, the subset_label_formatter is used create subset labels based on the subset sizes.
- subset_label_formatterCallable[[Tuple[bool], int | float], str]
The formatter used to create subset labels based on the subset sizes. The argument is ignored if subset_labels are not None.
- set_labelsOptional[list[str]]
A list of set labels. If none, defaults to the letters of the alphabet (capitalized).
- set_colorsOptional[list[ColorType]]
A corresponding list of matplotlib colors. If none, defaults to the default matplotlib color cycle.
- cost_function_objectivestr
The cost function objective; one of:
‘simple’ :
|x - y|‘squared’ :
(x - y)^2‘logarithmic’ :
|log(x + 1) - log(y + 1)|‘relative’ :
1 - min(x/y, y/x)‘inverse’ :
|1 / (x + epsilon) - 1 / (y + epsilon)|
Only applicable when instantiating an
EulerDiagram.- verbosebool
Print a report of the optimisation process. Only applicable when instantiating an
EulerDiagram.- axOptional[plt.Axes]
The matplotlib axis instance to draw onto. If none provided, a new figure with a single axis is instantiated.
- Attributes:
- originsNDArray
The circle origins.
- radiiNDArray
The circle radii.
- subset_geometriesdict[Tuple[bool], shapely.geometry.polygon.Polygon]
The dictionary mapping each subset to its shapely geometry.
- subset_artistsdict[tuple[bool], plt.Polygon]
The matplotlib Polygon patches representing each subset.
- subset_label_artistsdict[tuple[bool], plt.Text]
The matplotlib text objects used to label each subset.
- set_label_artistslist[plt.Text]
The matplotlib text objects used to label each set.
- axplt.Axes
The matplotlib axis instance.
- classmethod VennDiagram.as_wordcloud(sets, minimum_resolution=300, wordcloud_kwargs={}, *args, **kwargs)
Generate a set diagram with word clouds displaying the subset items.
- Parameters:
- setslist[set]
The sets.
- minimum_resolutionint
The minimum extent of the wordcloud image in pixels (i.e.
min(width, height)). Larger images take significantly longer to generate.- wordcloud_kwargsdict[str, Any]
Key word arguments passed through to wordcloud.WordCloud. Consult the wordcloud documentation [1] for a complete list. However, the following arguments are reserved:
mode = 'RGBA'background = Nonecolor_func = lambda *args, **kwargs : subset_color
- subset_labelsOptional[Mapping[Tuple[bool], str]]
A dictionary mapping each subset to its desired label or None. If None, the subset_label_formatter is used create subset labels based on the subset sizes.
- subset_label_formatterCallable[[Tuple[bool], int | float], str]
The formatter used to create subset labels based on the subset sizes. The argument is ignored if subset_labels are not None.
- set_labelsOptional[list[str]]
A list of set labels. If none, defaults to the letters of the alphabet (capitalized).
- set_colorsOptional[list[ColorType]]
A corresponding list of matplotlib colors. If none, defaults to the default matplotlib color cycle.
- cost_function_objectivestr
The cost function objective; one of:
‘simple’ :
|x - y|‘squared’ :
(x - y)^2‘logarithmic’ :
|log(x + 1) - log(y + 1)|‘relative’ :
1 - min(x/y, y/x)‘inverse’ :
|1 / (x + epsilon) - 1 / (y + epsilon)|
Only applicable when instantiating an
EulerDiagram.- verbosebool
Print a report of the optimisation process. Only applicable when instantiating an
EulerDiagram.- axOptional[plt.Axes]
The matplotlib axis instance to draw onto. If none provided, a new figure with a single axis is instantiated.
- Attributes:
- originsNDArray
The circle origins.
- radiiNDArray
The circle radii.
- subset_geometriesdict[Tuple[bool], shapely.geometry.polygon.Polygon]
The dictionary mapping each subset to its shapely geometry.
- subset_artistsdict[tuple[bool], plt.Polygon]
The matplotlib Polygon patches representing each subset.
- subset_label_artistsdict[tuple[bool], plt.Text]
The matplotlib text objects used to label each subset.
- set_label_artistslist[plt.Text]
The matplotlib text objects used to label each set.
- axplt.Axes
The matplotlib axis instance.
- wordcloudmatplotlib.image.AxesImage
The WordCloud image.
References