{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot XY\n\nThis demo shows how to set an optional x-vector to an 1D-plot.\n\nThe optional x-vector can be set by passing the optional x-vector as second argument to the ``plot1`` function\nor by setting the property ``xData`` of an existing plot. \nIf you want to add a x-vector to a plot of an ``N x M dataObject``\nyour x-vector has to be an ``dataObject`` of shape ``1 x M``.\nOnce you add an x-vector with a last dimension greater ``M`` the last points will be ignored.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom itom import plot\nfrom itom import plot1\nfrom itom import dataObject" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a spirale and plot it.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "angle = np.linspace(0, 10 * np.pi, num=500)\nx = dataObject([1, angle.shape[0]], dtype=\"float32\")\ny = dataObject([1, angle.shape[0]], dtype=\"float32\")\n\n# for the axis labels the valueDescription and valueUnit of the two data is used\nx.valueDescription = \"x data\"\nx.valueUnit = \"a.u.\"\n\ny.valueDescription = \"y data\"\ny.valueUnit = \"a.u.\"\n\nradius = angle**2\nx[:, :] = (radius * np.cos(angle)).astype(\"float32\")\ny[:, :] = (radius * np.sin(angle)).astype(\"float32\")\n\n# alternative 1: use the itom.plot1 method\nplot1(y, x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternative 2: Create a default line plot and then assign the\nx-coordinates to the ``xData`` property.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig = plot(y)\nfig[-1][\"xData\"] = x" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternative 3: like #2 but in one line\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot(y, properties={\"xData\": x})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This section shows you how to draw multiple lines of different length.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "yPoints = dataObject([4, 4], \"float32\")\nxPoints = dataObject([4, 4], \"float32\")\n\n# fill the dataObjects with nans to ignore values which are not needed\nyPoints[:, :] = np.nan\nxPoints[:, :] = np.nan\n\n# first line\nyPoints[0, 0] = 0\nxPoints[0, 0] = 0\nyPoints[0, 1] = 0\nxPoints[0, 1] = 1\nyPoints[0, 2] = 1\nxPoints[0, 2] = 1\nyPoints[0, 3] = 1\nxPoints[0, 3] = 0\n\n# second line\nyPoints[1, 0:2] = (0, 1)\nxPoints[1, 0:2] = (0, 1)\n\n# third line\nyPoints[2, 0] = 1\nxPoints[2, 0] = 0\nyPoints[2, 1] = 0\nxPoints[2, 1] = 1\n\n# fourth line\nyPoints[3, 0] = 1\nxPoints[3, 0] = 0\nyPoints[3, 1] = 1.5\nxPoints[3, 1] = 0.5\nyPoints[3, 2] = 1\nxPoints[3, 2] = 1\n\nplot1(yPoints, xPoints)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This section demonstrates how to draw multiple lines with a common array of x-coordinates.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "multipleY = dataObject([2, 4], \"float32\")\n# it is also possible to use a too long xData set. The last values will be ignored. \nsingleX = dataObject([1, 9], \"float32\") \n\nsingleX[0, 0:4] = (0, 1, 0.5, 0)\nmultipleY[0, :] = (0, 0, 1, 0)\nmultipleY[1, :] = (1, 1, 1.5, 1)\n\nplot1(multipleY, singleX)" ] }, { "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 }