{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Draw an InfiniteLine\n\nDemonstration of InfiniteLine visual.\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\nvert_line1 = scene.InfiniteLine(100, [1.0, 0.0, 0.0, 1.0],\n parent=viewbox.scene)\nvert_line2 = scene.InfiniteLine(549.2, [0.0, 1.0, 0.0, 1.0], vertical=True,\n parent=viewbox.scene)\n\n# add horizontal lines\nhor_line1 = scene.InfiniteLine(0.3, [1.0, 0.0, 1.0, 1.0], vertical=False,\n parent=viewbox.scene)\nhor_line2 = scene.InfiniteLine(-5.1, [1.0, 1.0, 0.0, 1.0], vertical=False,\n parent=viewbox.scene)\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 }