{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Tutorial 2: Data Plots\n", "\n", "This tutorial will talk about how to visualise the distributions that have been built in Tutorial 1. \n", "\n", "**NOTE FOR CONTRIBUTORS: Always clear all output before committing (``Cell`` > ``All Output`` > ``Clear``)**!" ] }, { "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 clusterking as ck" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we load the data created in Tutorial 1 in the folder output/cluster/ with the name tutorial_basics and pass it to the Data class." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d = ck.Data(\"output/tutorial_basics.sql\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The possible columns to be plotted can be found using:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.par_cols" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's also improve the styling of the variable on the x axis:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.configure_variable(\"q2\", axis_label=r\"$q^2\\ [\\mathrm{GeV}^2]$\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are now ready to visualise our created data: Let's start by drawing the histograms corresponding to the benchmark points of each clusters by typing:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.plot_dist();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also add more sample points to the plot (in addition to the benchmark point):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.plot_dist(clusters=[1, 2], nlines=5);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Save plots using the usual matplotlib syntax, e.g." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = d.plot_dist();\n", "fig.savefig(\"output/plots/test.pdf\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Showing the minima and maxima of all clusters is achieved with the plot_minmax method. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.plot_dist_minmax();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The same plot for clusters 2 and 3 only:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.plot_dist_minmax(clusters=[2,3]);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Box plots can be produced using the box_plot method:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.plot_dist_box();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Showing clusters 0 and 2 only:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d.plot_dist_box(clusters=[0, 2]);" ] } ], "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 }