{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot clusters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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": null, "metadata": {}, "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": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "d = Data(\"output/tutorial_basics.sql\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Manual Plotting" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = [\"red\", \"green\", \"blue\", \"pink\"]\n", "markers = [\"o\", \"v\", \"^\"]\n", "df = d.df\n", "clusters = df.cluster.unique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Manual 3d Plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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": {}, "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 ``ClusterPlot``" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
ClusterPlot
might change or disappear in the future.\n",
"