{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pick points and markers\n\nThis demo shows how you can pick points and markers in the ``itom`` plot.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from itom import dataObject\nfrom itom import plot2\nfrom itom import plotItem"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Pick Points demo**\n\nCreate a random 2 dimensional ``dataObject`` and plot it.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"obj = dataObject.randN([1024, 1024], \"int16\")\n\n[nr, h] = plot2(obj)\nh[\"title\"] = \"Showcase: pick marker\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This command let the user pick maximum 4 points (earlier break with space, esc aborts the selection).\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pickedPoints = dataObject()\nh.pickPoints(pickedPoints, 4)\n\nprint(\"coordinates of selected points: \")\nfor numPoint in range(pickedPoints.shape[1]):\n print(\"x: {}, y: {}\".format(pickedPoints[0, numPoint], pickedPoints[1, numPoint]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the ``dataObject`` again together with the previously selected points as ``marker``.\n\nThe second argument of ``plotMarkers`` is a style-string (this may change) ``[color, symbol, size]``:\n======= =====================================\ncolor {b, g, r, c, m, y, k, w}\nsymbol {., o, s, d, >, v, ^, <, x, *, +, h}\nsize any integer number\n======= =====================================\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"markers = dataObject([2, 3], \"float32\", data=[10.1, 20.2, 30.3, 7, 100, 500])\n[nr, h] = plot2(obj)\nh[\"title\"] = \"Showcase: plot the currently selected points\"\nh.call(\"plotMarkers\", pickedPoints, \"b+10\", \"setName\") # 'setName' is the name for this set of markers (optional)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Delete marker set\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"h.call(\"deleteMarkers\", \"setName\") # deletes given set\nh.call(\"deleteMarkers\", \"\") # deletes all sets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Paint geometric shapes**\n\nCreate a random 2 dimensional ``dataObject`` and plot it.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"obj = dataObject.randN([1024, 1024], \"int16\")\n[nr, h] = plot2(obj)\nh[\"title\"] = \"Showcase: paint 4 ellipses\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This command let the user pick maximum 4 points (earlier break with space, esc aborts the selection).\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"geometricShapes = h.drawAndPickElements(plotItem.PrimitiveEllipse, 4)\n\nprint(\"selected shapes:\")\nfor shape in geometricShapes:\n print(shape)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the ``dataObject`` again together with the previously painted ellipses ``geometricShapes``.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"[nr, hDrawInto] = plot2(obj)\nhDrawInto[\"title\"] = \"Showcase: plot painted ellipses\"\nhDrawInto.call(\"setGeometricShapes\", geometricShapes) # \"b\" and \"setname\" will be ignored anyway\nshapes = hDrawInto[\"geometricShapes\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n\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
}