{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Draw an LinearRegion\n\nDemonstration of LinearRegion visual. Allows drawing of infinite horizontal or\nvertical region for 2D plots.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\nimport numpy as np\nfrom vispy import app, scene\n\n# vertex positions of data to draw\nN = 200\npos = np.zeros((N, 2), dtype=np.float32)\nx_lim = [50., 750.]\ny_lim = [-2., 2.]\npos[:, 0] = np.linspace(x_lim[0], x_lim[1], N)\npos[:, 1] = np.random.normal(size=N)\n\n# color array\ncolor = np.ones((N, 4), dtype=np.float32)\ncolor[:, 0] = np.linspace(0, 1, N)\ncolor[:, 1] = color[::-1, 0]\n\ncanvas = scene.SceneCanvas(keys='interactive', show=True)\ngrid = canvas.central_widget.add_grid(spacing=0)\n\nviewbox = grid.add_view(row=0, col=1, camera='panzoom')\n\n# add some axes\nx_axis = scene.AxisWidget(orientation='bottom')\nx_axis.stretch = (1, 0.1)\ngrid.add_widget(x_axis, row=1, col=1)\nx_axis.link_view(viewbox)\ny_axis = scene.AxisWidget(orientation='left')\ny_axis.stretch = (0.1, 1)\ngrid.add_widget(y_axis, row=0, col=0)\ny_axis.link_view(viewbox)\n\n# add a line plot inside the viewbox\nline = scene.Line(pos, color, parent=viewbox.scene)\n\n# add vertical lines\ncolor = np.array([[1.0, 0.0, 0.0, 1.0],\n [0.0, 1.0, 0.0, 1.0],\n [0.0, 0.0, 1.0, 1.0],\n [0.0, 1.0, 0.0, 1.0],\n [1.0, 0.0, 0.0, 1.0],\n [0.0, 1.0, 0.0, 1.0]])\npos = np.array([100, 120, 140, 160, 180, 200], dtype=np.float32)\nvert_region1 = scene.LinearRegion(pos, color,\n parent=viewbox.scene)\n\nvert_region2 = scene.LinearRegion([549.2, 700], [0.0, 1.0, 0.0, 0.5],\n vertical=True,\n parent=viewbox.scene)\n\n# add horizontal lines\npos = np.array([0.3, 0.0, -0.1], dtype=np.float32)\nhor_region1 = scene.LinearRegion(pos, [1.0, 0.0, 0.0, 0.5],\n vertical=False,\n parent=viewbox.scene)\n\nhor_region2 = scene.LinearRegion([-5.1, -2.0], [0.0, 0.0, 1.0, 0.5],\n vertical=False,\n parent=viewbox.scene)\n\n\n# auto-scale to see the whole line.\nviewbox.camera.set_range()\n\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.19" } }, "nbformat": 4, "nbformat_minor": 0 }