.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/scene/colored_line.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_scene_colored_line.py: Changing Line Colors ==================== .. GENERATED FROM PYTHON SOURCE LINES 11-50 .. image-sg:: /gallery/scene/images/sphx_glr_colored_line_001.gif :alt: colored line :srcset: /gallery/scene/images/sphx_glr_colored_line_001.gif :class: sphx-glr-single-img .. code-block:: Python import itertools import numpy as np from vispy import app, scene from vispy.color import get_colormaps from vispy.visuals.transforms import STTransform colormaps = itertools.cycle(get_colormaps()) # vertex positions of data to draw N = 200 pos = np.zeros((N, 2), dtype=np.float32) pos[:, 0] = np.linspace(10, 390, N) pos[:, 1] = np.random.normal(size=N, scale=20, loc=0) canvas = scene.SceneCanvas(keys='interactive', size=(400, 200), show=True) # Create a visual that updates the line with different colormaps color = next(colormaps) line = scene.Line(pos=pos, color=color, method='gl') line.transform = STTransform(translate=[0, 140]) line.parent = canvas.central_widget text = scene.Text(color, bold=True, font_size=24, color='w', pos=(200, 40), parent=canvas.central_widget) def on_timer(event): global colormaps, line, text, pos color = next(colormaps) line.set_data(pos=pos, color=color) text.text = color timer = app.Timer(.5, connect=on_timer, start=True) if __name__ == '__main__': canvas.app.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.055 seconds) .. _sphx_glr_download_gallery_scene_colored_line.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: colored_line.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: colored_line.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_