{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Highlighting selected subsets\n\n\nDemonstrates use of the `style_subsets` method to mark some subsets as\ndifferent.\n\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "from matplotlib import pyplot as plt\nfrom upsetplot import generate_counts, UpSet\n\nexample = generate_counts()"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "Subsets can be styled by the categories present in them, and a legend\ncan be optionally generated.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "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()"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "... or styling can be applied by the categories absent in a subset.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "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()"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "... or their size or degree.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "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()"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "Multiple stylings can be applied with different criteria in the same\nplot.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "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()"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.18", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}