{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Highlighting selected subsets\n\nDemonstrates use of the `style_subsets` method to mark some subsets as\ndifferent.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from matplotlib import pyplot as plt\nfrom upsetplot import generate_counts, UpSet\n\nexample = generate_counts()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Subsets can be styled by the categories present in them, and a legend\ncan be optionally generated.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "upset = UpSet(example)\nupset.style_subsets(present=[\"cat1\", \"cat2\"],\n                    facecolor=\"blue\",\n                    label=\"special\")\nupset.plot()\nplt.suptitle(\"Paint blue subsets including both cat1 and cat2; show a legend\")\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "... or styling can be applied by the categories absent in a subset.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "upset = UpSet(example, orientation=\"vertical\")\nupset.style_subsets(present=\"cat2\", absent=\"cat1\", edgecolor=\"red\",\n                    linewidth=2)\nupset.plot()\nplt.suptitle(\"Border for subsets including cat2 but not cat1\")\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "... or their size or degree.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "upset = UpSet(example)\nupset.style_subsets(min_subset_size=1000,\n                    facecolor=\"lightblue\", hatch=\"xx\",\n                    label=\"big\")\nupset.plot()\nplt.suptitle(\"Hatch subsets with size >1000\")\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Multiple stylings can be applied with different criteria in the same\nplot.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "upset = UpSet(example, facecolor=\"gray\")\nupset.style_subsets(present=\"cat0\", label=\"Contains cat0\", facecolor=\"blue\")\nupset.style_subsets(present=\"cat1\", label=\"Contains cat1\", hatch=\"xx\")\nupset.style_subsets(present=\"cat2\", label=\"Contains cat2\", edgecolor=\"red\")\n\n# reduce legend size:\nparams = {'legend.fontsize': 8}\nwith plt.rc_context(params):\n    upset.plot()\nplt.suptitle(\"Styles for every category!\")\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}