.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "sphinx_gallery_output/plot_04_customization.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_sphinx_gallery_output_plot_04_customization.py: Colour & label customisation ============================ Colours ------- The primary way to specify set colours is through the :code:`set_colors` argument. Each subset is then coloured by blending the colours of the corresponding super-sets. .. GENERATED FROM PYTHON SOURCE LINES 13-32 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from matplotlib_set_diagrams import ( VennDiagram, ) subset_sizes = { (1, 0) : 1, (1, 1) : 2, (0, 1) : 3, } set_colors = ["tab:blue", "tab:red"] VennDiagram(subset_sizes, set_colors=set_colors) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_001.png :alt: plot 04 customization :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-36 To change the colour of a subset independently of the set colors, access the corresponding matplotlib :code:`Polygon` artist, and use the standard matplotlib methods. .. GENERATED FROM PYTHON SOURCE LINES 36-46 .. code-block:: Python fig, ax = plt.subplots() diagram = VennDiagram(subset_sizes, set_colors=set_colors, ax=ax) artist = diagram.subset_artists[(1, 1)] artist.set_facecolor("tab:purple") artist.set_edgecolor("tab:pink") artist.set_linewidth(5) artist.set_alpha(0.9) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_002.png :alt: plot 04 customization :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-50 The outlines of the sets are invisible by default. To show them, access the corresponding matplotlib :code:`Circle` artists, and set their visibility to True. .. GENERATED FROM PYTHON SOURCE LINES 50-57 .. code-block:: Python fig, ax = plt.subplots() diagram = VennDiagram(subset_sizes, set_colors=set_colors, ax=ax) for artist in diagram.set_artists: artist.set_visible(True) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_003.png :alt: plot 04 customization :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-59 The set artists can be styled using the standard matplotlib methods. .. GENERATED FROM PYTHON SOURCE LINES 59-68 .. code-block:: Python fig, ax = plt.subplots() diagram = VennDiagram(subset_sizes, set_colors=set_colors, ax=ax) for artist in diagram.set_artists: artist.set_visible(True) artist.set_edgecolor("#2c404c") # off-black artist.set_linewidth(0.5) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_004.png :alt: plot 04 customization :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 69-76 Labels ------ By default, sets are labelled using the letters of the alphabet, and subsets are annotated with their size (as in the examples above). Set labels can be set explicitly using the :code:`set_labels` argument, subset labels by providing a :code:`subset_labels` argument: .. GENERATED FROM PYTHON SOURCE LINES 77-88 .. code-block:: Python sets = [{"rhombus", "square"}, {"square", "rectangle"}] set_labels = ["equilateral", "rectangular"] subset_labels = { (1, 0) : "rhombus", (1, 1) : "square", (0, 1) : "rectangle", } VennDiagram.from_sets(sets, set_labels=set_labels, subset_labels=subset_labels) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_005.png :alt: plot 04 customization :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-92 If the subset labels are a function of the subset ID and/or subset size, the :code:`subset_label_formatter` can be used to specify the subset label. For example, to label subsets with the percentage of the total, use the following: .. GENERATED FROM PYTHON SOURCE LINES 92-106 .. code-block:: Python subset_sizes = { (1, 0) : 1, (1, 1) : 2, (0, 1) : 3, } total_size = np.sum(list(subset_sizes.values())) def formatter(subset_id, subset_size): return f"{subset_size / total_size * 100 : .1f}%" VennDiagram(subset_sizes, subset_label_formatter=formatter) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_006.png :alt: plot 04 customization :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-110 Finally, the set label "artists" and subset labels "artists" are just matplotlib :code:`Text` objects, which can be manipulated directly using the standard matplotlib text object methods: .. GENERATED FROM PYTHON SOURCE LINES 110-131 .. code-block:: Python set_labels = ["Lorem", "ipsum"] set_colors = ["tab:blue", "tab:red"] subset_sizes = { (1, 0) : 1, (1, 1) : 2, (0, 1) : 3, } diagram = VennDiagram(subset_sizes, set_labels=set_labels, set_colors=set_colors) # manipulate text objects using standard matplotlib methods: font_weights = ["light", "bold"] for ii, text in enumerate(diagram.set_label_artists): text.set_color(set_colors[ii]) text.set_weight(font_weights[ii]) for subset_id, size in subset_sizes.items(): text = diagram.subset_label_artists[subset_id] text.set_fontsize(10 * size) plt.show() .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_007.png :alt: plot 04 customization :srcset: /sphinx_gallery_output/images/sphx_glr_plot_04_customization_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.292 seconds) .. _sphx_glr_download_sphinx_gallery_output_plot_04_customization.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_customization.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_customization.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_customization.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_