Skip to content
Snippets Groups Projects
demand-metric-plot.ipynb 5.07 KiB
Newer Older
{
 "cells": [
  {
   "source": [
    "# Theodolite Analysis - Plotting the Demand Metric\n",
    "\n",
    "This notebook creates a plot, showing scalability as a function that maps load intensities to the resources required for processing them. It is able to combine multiple such plots in one figure, for example, to compare multiple systems or configurations.\n",
    "\n",
    "The notebook takes a CSV file for each plot mapping load intensities to minimum required resources, computed by the `demand-metric-plot.ipynb` notebook."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "source": [
    "First, we need to import some libraries, which are required for creating the plots."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "from functools import reduce\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.ticker import FuncFormatter\n",
    "from matplotlib.ticker import MaxNLocator"
   ]
  },
  {
   "source": [
    "We need to specify the directory, where the demand CSV files can be found, and a dictionary that maps a system description (e.g. its name) to the corresponding CSV file (prefix). To use Unicode narrow non-breaking spaces in the description format it as `u\"1000\\u202FmCPU\"`."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "results_dir = '<path-to>/results'\n",
    "\n",
    "experiments = {\n",
    "    'System XYZ': 'exp200',\n",
    "}\n"
   ]
  },
  {
   "source": [
    "Now, we combie all systems described in `experiments`."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataframes = [pd.read_csv(os.path.join(results_dir, f'{v}_demand.csv')).set_index('load').rename(columns={\"resources\": k}) for k, v in experiments.items()]\n",
    "\n",
    "df = reduce(lambda df1,df2: df1.join(df2,how='outer'), dataframes)"
   ]
  },
  {
   "source": [
    "We might want to display the mappings before we plot it."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df"
   ]
  },
  {
   "source": [
    "The following code creates a MatPlotLib figure showing the scalability plots for all specified systems. You might want to adjust its styling etc. according to your preferences. Make sure to also set a filename."
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.style.use('ggplot')\n",
    "plt.rcParams['pdf.fonttype'] = 42 # TrueType fonts\n",
    "plt.rcParams['ps.fonttype'] = 42 # TrueType fonts\n",
    "plt.rcParams['axes.facecolor']='w'\n",
    "plt.rcParams['axes.edgecolor']='555555'\n",
    "#plt.rcParams['ytick.color']='black'\n",
    "plt.rcParams['grid.color']='dddddd'\n",
    "plt.rcParams['axes.spines.top']='false'\n",
    "plt.rcParams['axes.spines.right']='false'\n",
    "plt.rcParams['legend.frameon']='true'\n",
    "plt.rcParams['legend.framealpha']='1'\n",
    "plt.rcParams['legend.edgecolor']='1'\n",
    "plt.rcParams['legend.borderpad']='1'\n",
    "\n",
    "@FuncFormatter\n",
    "def load_formatter(x, pos):\n",
    "    return f'{(x/1000):.0f}k'\n",
    "\n",
    "markers = ['s', 'D', 'o', 'v', '^', '<', '>', 'p', 'X']\n",
    "\n",
    "def splitSerToArr(ser):\n",
    "    return [ser.index, ser.as_matrix()]\n",
    "\n",
    "plt.figure()\n",
    "#plt.figure(figsize=(4.8, 3.6)) # For other plot sizes\n",
    "#ax = df.plot(kind='line', marker='o')\n",
    "for i, column in enumerate(df):\n",
    "    plt.plot(df[column].dropna(), marker=markers[i], label=column)\n",
    "plt.legend()\n",
    "ax = plt.gca()\n",
    "#ax = df.plot(kind='line',x='dim_value', legend=False, use_index=True)\n",
    "ax.set_ylabel('number of instances')\n",
    "ax.set_xlabel('messages/second')\n",
    "ax.set_ylim(ymin=0)\n",
    "#ax.set_xlim(xmin=0)\n",
    "ax.yaxis.set_major_locator(MaxNLocator(integer=True))\n",
    "ax.xaxis.set_major_formatter(FuncFormatter(load_formatter))\n",
    "\n",
    "plt.savefig('temp.pdf', bbox_inches='tight')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "version": "3.8.5-final"
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3,
  "kernelspec": {
   "name": "python37064bitvenvvenv6c432ee1239d4f3cb23f871068b0267d",
   "display_name": "Python 3.7.0 64-bit ('.venv': venv)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}