{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Embedded plots\n\nThis script shows how to use embedded static line plots in ``itom`` in a single GUI.\nThe z-slicing tool will display its line output in a ``1D`` line plot below the ``2D``\nplot (becomes visible then). The line cut tool will open a new ``1D`` line plot.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from itom import dataObject\nfrom itomUi import ItomUi\nfrom itom import ui\n\n\nclass EmbeddedPlots(ItomUi):\n def __init__(self, dataObj: dataObject):\n\n uiFile = r\"embedded2DwLinePlot.ui\"\n ItomUi.__init__(\n self,\n uiFile,\n ui.TYPEWINDOW,\n childOfMainWindow=True,\n deleteOnClose=True,\n )\n\n self.gui.plot2D[\"source\"] = dataObj\n\n def show(self, modalLevel=0):\n self.gui.show(modalLevel)\n\n @ItomUi.autoslot(\"bool\")\n def on_radioNothing_toggled(self, checked: bool):\n if checked:\n self.gui.plot2D[\"lineCutPlotItem\"] = None\n self.gui.plot2D[\"zSlicePlotItem\"] = None\n self.gui.group1D[\"enabled\"] = False\n self.gui.plot1D[\"source\"] = dataObject()\n\n @ItomUi.autoslot(\"bool\")\n def on_radioZCut_toggled(self, checked: bool):\n if checked:\n self.gui.plot2D[\"lineCutPlotItem\"] = None\n self.gui.plot2D[\"zSlicePlotItem\"] = self.gui.plot1D\n self.gui.group1D[\"enabled\"] = True\n\n @ItomUi.autoslot(\"bool\")\n def on_radioLineCut_toggled(self, checked: bool):\n if checked:\n # if the same plot is used for different sub-plots, invalidate one type at first\n # before you assign the new one\n self.gui.plot2D[\"zSlicePlotItem\"] = None # invalidating\n self.gui.plot2D[\"lineCutPlotItem\"] = self.gui.plot1D # assigning new one\n self.gui.group1D[\"enabled\"] = True\n\n\ndef createSampleObject():\n tempData = dataObject.randN([10, 50, 50], \"float32\") * 100\n for i in range(0, tempData.shape[0]):\n # tempData[i, :, :] += i - tempData.shape[0] / 20\n tempData[i, :, 25:50] += 200\n\n return tempData\n\n\nif __name__ == \"__main__\":\n modeID = 1 # use 0 for lateral slice example or 1 for zSlice example\n win = EmbeddedPlots(createSampleObject())\n win.show()" ] }, { "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 }