{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Spheres and Sticks\n\nDraw spherical Markers with Tube meshes connecting them.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom vispy import app, scene\n\n# Create canvas and view\ncanvas = scene.SceneCanvas(keys='interactive', size=(600, 600), show=True)\nview = canvas.central_widget.add_view()\nview.camera = scene.cameras.ArcballCamera(fov=0)\nview.camera.scale_factor = 500\n\n# Prepare data\nnp.random.seed(57983)\ndata = np.random.normal(size=(40, 3), loc=0, scale=100)\nsize = np.random.rand(40) * 100\ncolors = np.random.rand(40, 3)\n\ndata = np.concatenate([data, [[0, 0, 0]]], axis=0)\nsize = np.concatenate([size, [100]], axis=0)\ncolors = np.concatenate([colors, [[1, 0, 0]]], axis=0)\n\n\n# Create and show visual\nvis = scene.visuals.Markers(\n pos=data,\n size=100,\n antialias=0,\n face_color=colors,\n edge_color='white',\n edge_width=0,\n scaling=True,\n spherical=True,\n)\nvis.parent = view.scene\n\nlines = np.array([[data[i], data[-1]]\n for i in range(len(data) - 1)])\nline_vis = []\n\nfor line in lines:\n vis2 = scene.visuals.Tube(line, radius=5)\n vis2.parent = view.scene\n line_vis.append(vis2)\n\nif __name__ == \"__main__\":\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 }