{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Plotting discrete variables as stacked bar charts\n\n\nCurrently, a somewhat contrived example of `add_stacked_bars`.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "import pandas as pd\nfrom upsetplot import UpSet\nfrom matplotlib import pyplot as plt\nfrom matplotlib import cm\n\nTITANIC_URL = 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv'  # noqa\ndf = pd.read_csv(TITANIC_URL)\n# Show UpSet on survival and first classs\ndf = df.set_index(df.Survived == 1).set_index(df.Pclass == 1, append=True)\n\nupset = UpSet(df,\n              intersection_plot_elements=0)  # disable the default bar chart\nupset.add_stacked_bars(by=\"Sex\", colors=cm.Pastel1,\n                       title=\"Count by gender\", elements=10)\nupset.plot()\nplt.suptitle(\"Gender for first class and survival on Titanic\")\nplt.show()\n\n\nupset = UpSet(df, show_counts=True, orientation=\"vertical\",\n              intersection_plot_elements=0)\nupset.add_stacked_bars(by=\"Sex\", colors=cm.Pastel1,\n                       title=\"Count by gender\", elements=10)\nupset.plot()\nplt.suptitle(\"Same, but vertical, with counts shown\")\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"
      }
    }
  }
}