{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Draw pickers 1D plot\n\n\nThis demo shows how to programatically set pickers\nto the line of a 1D plot.\n\nThe most important ``slots`` for these features are implemented\nin the designer widget ``itom1dqwtplot``:\n\n```python\nmyPlotHandle.call(\"setPicker\", axis-values [, curveIndex = 0, physicalCoordinates=True])\nmyPlotHandle.call(\"appendPicker\", axis-values [, curveIndex = 0, physicalCoordinates=True])\nmyPlotHandle.call(\"deletePicker\", [index])\n```\n``setPicker`` and ``appendPicker`` are used to set a new set of pickers or append further\npickers to the existing set of pickers. ``deletePicker`` is used to clear existing pickers.\n\nFor settings pickers, a list or tuple of axis-values has to be given. The corresponding value\nis calculated based on the current curve, that is displayed. In order to stick the new picker\nto another than the first curve, use another ``curveIndex`` parameter. Usually, the axis-values\nare considered to be given in physical coordinates (which are displayed in the coordinate system).\n\nIf you want to give the coordinate of a picker in real pixel-coordinates of the ``dataObject``,\nset ``physicalCoordinates`` to False.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom itom import plot \nfrom itom import dataObject\n\n\ndef pickerChangedSlot(pickerIdx, posX, posY, curveIdx):\n print(\n \"picker %i changed. New pos: (%.2f, %.2f), curve: %i\"\n % (pickerIdx, posX, posY, curveIdx)\n )\n\n\n# create demo data\n# 1d sine\nsine = np.sin(np.arange(0, 10 * np.pi, (1 / 20) * np.pi))\nsine2 = np.sin(np.arange(0, 5 * np.pi, (1 / 40) * np.pi))\ntwosines = dataObject([2, len(sine)], \"float64\")\ntwosines[0, :] = sine\ntwosines[1, :] = sine2\n\ntwosines.axisScales = (1, np.pi / 20)\n\n[i, h] = plot(twosines, \"itom1dqwtplot\")\n\nh.connect(\"pickerChanged(int,double,double,int)\", pickerChangedSlot)\n\n# increase the maximum number of pickers to 7\nh[\"pickerLimit\"] = 7\n\n# set two pickers to the first curve\nh.call(\"setPicker\", (1.5 * np.pi, 2.5 * np.pi), 0)\n\n# set two pickers to the second curve\nh.call(\"appendPicker\", (40, 80, 120, 160, 200), 1, False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n" ] } ], "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.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }