{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Display an Isocurve\n\nSimple use of SceneCanvas to display an Isocurve visual.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\nfrom vispy import app, scene, visuals\nfrom vispy.util.filter import gaussian_filter\nimport numpy as np\n\ncanvas = scene.SceneCanvas(keys='interactive', title='Isocurve(s) overlayed '\n 'over Random Image Example')\ncanvas.size = 800, 600\ncanvas.show()\n\n# Set up a viewbox to display the image with interactive pan/zoom\nview = canvas.central_widget.add_view()\n\n# Create the image\nimg_data = np.empty((200, 100, 3), dtype=np.ubyte)\nnoise = np.random.normal(size=(200, 100), loc=50, scale=150)\nnoise = gaussian_filter(noise, (4, 4, 0))\nimg_data[:] = noise[..., np.newaxis]\nimage = scene.visuals.Image(img_data, parent=view.scene)\n# move image behind curves\nimage.transform = visuals.transforms.STTransform(translate=(0, 0, 0.5))\n\n# level and color setup\nlevels = [40, 50, 60]\ncolor_lev = [(1, 0, 0, 1),\n (1, 0.5, 0, 1),\n (1, 1, 0, 1)]\n\n# Create isocurve, make a child of the image to ensure the two are always\n# aligned.\ncurve = scene.visuals.Isocurve(noise, levels=levels, color_lev=color_lev,\n parent=view.scene)\n\n# Set 2D camera\nview.camera = scene.PanZoomCamera(aspect=1)\n# the camera will scale to the contents in the scene\nview.camera.set_range()\n\nif __name__ == '__main__' and sys.flags.interactive == 0:\n app.run()" ] } ], "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.9.20" } }, "nbformat": 4, "nbformat_minor": 0 }