{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Changing Line Colors\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import itertools\nimport numpy as np\n\nfrom vispy import app, scene\nfrom vispy.color import get_colormaps\nfrom vispy.visuals.transforms import STTransform\n\ncolormaps = itertools.cycle(get_colormaps())\n\n# vertex positions of data to draw\nN = 200\npos = np.zeros((N, 2), dtype=np.float32)\npos[:, 0] = np.linspace(10, 390, N)\npos[:, 1] = np.random.normal(size=N, scale=20, loc=0)\n\n\ncanvas = scene.SceneCanvas(keys='interactive', size=(400, 200), show=True)\n\n# Create a visual that updates the line with different colormaps\ncolor = next(colormaps)\nline = scene.Line(pos=pos, color=color, method='gl')\nline.transform = STTransform(translate=[0, 140])\nline.parent = canvas.central_widget\n\ntext = scene.Text(color, bold=True, font_size=24, color='w',\n pos=(200, 40), parent=canvas.central_widget)\n\n\ndef on_timer(event):\n global colormaps, line, text, pos\n color = next(colormaps)\n line.set_data(pos=pos, color=color)\n text.text = color\n\ntimer = app.Timer(.5, connect=on_timer, start=True)\n\n\nif __name__ == '__main__':\n canvas.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 }