{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Draw markers\n\nIn this example, you will learn how to mark points in ``1d`` or ``2d`` plots\nwith markers of varying shapes, colors and sizes. Multiple markers\ncan be set in one group with a corresponding name. It is also possible\nto delete such groups using its name again.\n\nFor this feature, the designer plugin ``itom1dqwtplot`` and ``itom2dqwtplot``\nhave the slots ``plotMarkers`` and ``deleteMarkers``.\n\nThe slot ``deleteMarkers`` is defined as follows:\n\n```python\nmyPlot.call(\"deleteMarkers\", groupname)\n```\nThe slot ``plotMarkers`` is defined as follows:\n\n```python\nmyPlot.call(\"plotMarkers\", points, style, groupname = \"\")\n```\nwhere:\n\n* points is a 2xN ``dataObject`` with N points. The first row is the x-coordinate, the 2nd row the y-coordinate.\n* style is defined as follows: ``r*20`` or ``r*20;2``, where ``r`` is the color, ``*`` the shape and ``20`` the size of the shape in pixel. Optionally 2 is the line width. \n\nPossible colors are:\n \n== =======\nb blue\ng green\nr red\nc cyan\nm magenta\ny yellow\nk black\nw white\n== =======\n \nPossible shapes are:\n \n== ===========================\n. point\no ellipse\ns square\nd diamond\n> triangle, tip to the right\nv triangle, tip to the bottom\n^ triangle, tip to the top\n< triangle, tip to the left\nx x-cross\n\\* star\n\\+ cross\nh hexagon\n== ===========================\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom itom import dataObject\nfrom itom import plot\n\n# 1d sine\nsine = dataObject(np.sin(np.arange(0, 10 * np.pi, (1 / 20) * np.pi)))\n\n# 3d object with two different chessboards in both planes\nchessboard = dataObject.zeros([2, 1024, 1024], \"uint8\")\ncolor = 0\nfor r in range(0, 1024, 64):\n color = 255 if color == 0 else 0 # invert color\n for c in range(0, 1024, 64):\n chessboard[0, r : r + 64, c : c + 64] = color\n color = 255 if color == 0 else 0 # invert color\nfor r in range(0, 1024, 128):\n color = 255 if color == 0 else 0 # invert color\n for c in range(0, 1024, 128):\n chessboard[1, r : r + 128, c : c + 128] = color\n color = 255 if color == 0 else 0 # invert color\n\n[i1, h1] = plot(sine)\n[i2, h2] = plot(chessboard)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mark all zero values of the sine with red stars (size: 20).\nThe name of this set of 11 points is called *zero-points*.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "zeros = dataObject.zeros([2, 11], \"float32\")\nfor i in range(0, 11):\n zeros[0, i] = 20 * i\nh1.call(\"plotMarkers\", zeros, \"r*20\", \"zero-points\")\n\n# in order to delete the set, call\nh1.call(\"deleteMarkers\", \"zero-points\")\n# and set it again\nh1.call(\"plotMarkers\", zeros, \"r*20\", \"zero-points\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mark all local maximas of the sine with green dots (size: 5).\nThe name of this set is *local-maximas*.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "maximas = dataObject.zeros([2, 5], \"float32\")\nfor i in range(0, 5):\n maximas[1, i] = 1\n maximas[0, i] = 10 + 40 * i\nh1.call(\"plotMarkers\", maximas, \"gs5\", \"local-maximas\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Put crosses at all corner points of the chessboard.\nPlease consider, that both chessboards in both planes have different\nmarker patterns.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "[X1, Y1] = np.meshgrid(range(64, 1024, 64), range(64, 1024, 64))\n[X2, Y2] = np.meshgrid(range(128, 1024, 128), range(128, 1024, 128))\n\ncorners1 = dataObject([2, 225], \"int32\")\ncorners1[0, :] = X1.flatten()\ncorners1[1, :] = Y1.flatten()\n\ncorners2 = dataObject([2, 49], \"int32\")\ncorners2[0, :] = X2.flatten()\ncorners2[1, :] = Y2.flatten()\n\nh2.call(\"plotMarkers\", corners1, \"r+25;2\", \"corners1\", 0) # draw to plane 0 only\nh2.call(\"plotMarkers\", corners2, \"c+25\", \"corners2\", 1) # draw to plane 1 only" ] }, { "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 }