{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot clusters" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Magic\n", "%matplotlib inline\n", "# Reload modules whenever they change\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "# Make clusterking package available even without installation\n", "import sys\n", "sys.path = [\"../../\"] + sys.path" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pandas as pd\n", "import os.path\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d import Axes3D\n", "from pathlib import Path\n", "\n", "from clusterking.plots import ClusterPlot\n", "from clusterking.data.data import Data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": false }, "outputs": [], "source": [ "d = Data(\"output/cluster/\", \"tutorial_basics\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Manual Plotting" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clusters = list(df['cluster'].unique())\n", "colors = [\"red\", \"green\", \"blue\", \"pink\"]\n", "markers = [\"o\", \"v\", \"^\"]\n", "df = d.df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Manual 3d Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "ax = plt.figure().gca(projection='3d')\n", "ax.set_xlabel('CVL_bctaunutau')\n", "ax.set_ylabel('sl')\n", "ax.set_zlabel('CT_bctaunutau')\n", "\n", "for index, cluster in enumerate(clusters):\n", " df_cluster = df[df['cluster'] == cluster]\n", " ax.scatter(\n", " df_cluster['CVL_bctaunutau'], \n", " df_cluster['CSL_bctaunutau'], \n", " df_cluster['CT_bctaunutau'], \n", " color=colors[cluster % len(colors)], \n", " marker=markers[cluster % len(markers)],\n", " label=cluster\n", " )\n", "\n", "plt.legend(loc='upper left');\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Manual 2d Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "ax.set_xlabel('CVL_bctaunutau')\n", "ax.set_ylabel('CSL_bctaunutau')\n", "\n", "# fix remaining Wilson coefficients\n", "t_value_index = 1\n", "t_value = df['CT_bctaunutau'].unique()[t_value_index]\n", "\n", "for index, cluster in enumerate(clusters):\n", " df_cluster = df[df['cluster'] == cluster]\n", " df_cluster = df_cluster[df_cluster['CT_bctaunutau'] == t_value]\n", " ax.scatter(\n", " df_cluster['CVL_bctaunutau'], \n", " df_cluster['CSL_bctaunutau'], \n", " color=colors[cluster % len(colors)], \n", " marker=markers[cluster % len(markers)],\n", " label=cluster\n", " )\n", "\n", "plt.legend(bbox_to_anchor=(1.2, 1.0));\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using ``plot_clusters``" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set up the plotter:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp = ClusterPlot(d)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp.draw_legend=True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3D plots" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Scatter plot: The list is the list of the columns on the axes. \n", "Changing the order of the columns will turn around the cube. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "cp.scatter(['CVL_bctaunutau', 'CSL_bctaunutau', 'CT_bctaunutau'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If it is still not easy to get an overview, use the ``clusters`` argument to limit ourselves to certain clusters." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "scrolled": false }, "outputs": [], "source": [ "cp.scatter(['CVL_bctaunutau', 'CSL_bctaunutau', 'CT_bctaunutau'], clusters=[0, 2])" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp.savefig(\"/home/fuchur/scatter_3d_02.png\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If only two columns are given, several cuts will be presented (up to 16 by default):" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2D cuts" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp.scatter(['CVL_bctaunutau', 'CSL_bctaunutau'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, we can also limit ourselves on the clusters that we want to display:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "scrolled": false }, "outputs": [], "source": [ "cp.scatter(['CVL_bctaunutau', 'CSL_bctaunutau'], clusters=[1,2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If many wilson points are available, it is better to switch to a 'fill' plot:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp.fill(['CVL_bctaunutau', 'CSL_bctaunutau'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### More configuration" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Several options to configure the the ClusterPlot object can be changed after the object has been initialized." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The number of plots for the 'slices' by" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp.max_subplots" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's change that (note that no warning is issued when trying to set a non-existing property, so do be careful with your typing):" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp.max_subplots = " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And try it out:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "cp.scatter(['CVL_bctaunutau', 'CSL_bctaunutau'])" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "cp.fill(['CVL_bctaunutau', 'CSL_bctaunutau'])" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": true }, "outputs": [], "source": [ "cp.savefig(\"/home/fuchur/fill_2d.png\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To see all options, see the ``Attribute`` section of the help." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "scrolled": true }, "outputs": [], "source": [ "help(cp)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.5.2" } }, "nbformat": 4, "nbformat_minor": 1 }