{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Grouping data by category\n\nWhen plotting, its useful to have a way to color points by some category or\nvariable. Hypertools does this using the `hue` kwarg, which takes a list\nof string category labels or numerical values. If text labels are passed, the\ndata is restructured according to those labels and plotted in different colors\naccording to your color palette. If numerical values are passed, the values\nare binned (default resolution: 100) and plotted according to your color\npalette.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Code source: Andrew Heusser\n# License: MIT\n\n# import\nimport hypertools as hyp\nimport numpy as np\n\n# load example data\ngeo = hyp.load('weights_sample')\ndata = geo.get_data()\n\n# simulate random groups\nhue=[]\nfor idx,i in enumerate(data):\n tmp=[]\n for iidx,ii in enumerate(i):\n tmp.append(int(np.random.randint(1000, size=1)))\n hue.append(tmp)\n\n# plot\ngeo.plot(fmt='.', hue=hue)" ] } ], "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.12.4" } }, "nbformat": 4, "nbformat_minor": 0 }