{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plotting routines in `touchsim`\n", "The `touchsim` package uses `holoviews` for plotting." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import touchsim as ts\n", "from touchsim.plotting import plot\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Hand model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot() # short for plot(ts.hand_surface)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Regions labels and the coordinate system can be overlaid on the plot." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot(tags=True,coord=10) # coord sets the lengths of the coordinate axes in mm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualising `AfferentPopulation` objects" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a = ts.affpop_hand(region='D2d')\n", "plot(a,size=10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Spatial plots can be overlaid on the hand outline or individual parts of it" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_,(ax1,ax2,ax3) = plt.subplots(1,3)\n", "plt.sca(ax1)\n", "plot(region='D2d')\n", "plot(a['SA1'],size=10)\n", "\n", "plt.sca(ax2)\n", "plot(region='D2d')\n", "plot(a['RA'],size=10)\n", "\n", "plt.sca(ax3)\n", "plot(region='D2d')\n", "plot(a['PC'],size=10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualising `Stimulus` objects\n", "Plotting a `Stimulus` object shows the trace of all pins by default." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s = ts.stim_ramp(len=0.25,amp=.1,ramp_len=0.05)\n", "plot(s)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s += ts.stim_sine(freq=25.,len=.25,loc=[1.,1.])\n", "plot(s)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pin positions can also be shown spatially." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s = ts.stim_indent_shape(ts.shape_circle(hdiff=0.5,pins_per_mm=2,radius=3),ts.stim_ramp(len=0.1))\n", "plot(region='D2d')\n", "plot(s,spatial=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualising `Response` objects\n", "Plotting a `Response` object shows the spike trains of all included neurons" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a = ts.affpop_hand(region='D2')\n", "s = ts.stim_sine(freq=50.,amp=0.1,len=0.5)\n", "r = a.response(s)\n", "plot(r)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Responses can be shown within a certain time window." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot(r,bin=[0,0.2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Responses can also be plotted spatially, in which case the size of each dot scaled with the neuron's firing rate." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot(region='D2')\n", "plot(r,spatial=True,scaling_factor=.25)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, firing rate can be indicated by color instead:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_,(ax1,ax2) = plt.subplots(1,2)\n", "plt.sca(ax1)\n", "plot(region='D2')\n", "plot(r[r.aff['RA']],spatial=True,scale=False)\n", "\n", "plt.sca(ax2)\n", "plot(region='D2')\n", "plot(r[r.aff['PC']],spatial=True,scale=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Advanced example (might be slow to compute)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "contact_locs = np.zeros((2,2))\n", "contact_locs[0] = np.array([0.,0.])\n", "contact_locs[1] = np.array([150.,0])\n", " \n", "a = ts.affpop_hand(noisy=False)\n", "s = ts.stim_indent_shape(contact_locs,ts.stim_ramp(amp=0.75,len=.2,ramp_len=0.05,ramp_type='lin',pin_radius=5.,pad_len=0.025))\n", "r = a.response(s)\n", "plot(r)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.13.2" } }, "nbformat": 4, "nbformat_minor": 4 }