{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plot data with different styles\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n\nfrom vispy import plot as vp\n\nfig = vp.Fig(size=(600, 500), show=False)\n\n# Plot the target square wave shape\nx = np.linspace(0, 10, 1000)\ny = np.zeros(1000)\ny[1:500] = 1\ny[500:-1] = -1\nline = fig[0, 0].plot((x, y), width=3, color='k',\n title='Square Wave Fourier Expansion', xlabel='x',\n ylabel='4/\u03c0 \u03a3[ 1/n sin(n\u03c0x/L) | n=1,3,5,...]')\n\ny = np.zeros(1000)\nL = 5\ncolors = [(0.8, 0, 0, 1),\n (0.8, 0, 0.8, 1),\n (0, 0, 1.0, 1),\n (0, 0.7, 0, 1), ]\nplot_nvals = [1, 3, 7, 31]\nfor i in range(16):\n n = i * 2 + 1\n y += (4. / np.pi) * (1. / n) * np.sin(n * np.pi * x / L)\n if n in plot_nvals:\n tmp_line = fig[0, 0].plot((x, y), color=colors[plot_nvals.index(n)],\n width=2)\n tmp_line.update_gl_state(depth_test=False)\n\nlabelgrid = fig[0, 0].view.add_grid(margin=10)\n\nbox = vp.Widget(bgcolor=(1, 1, 1, 0.6), border_color='k')\nbox_widget = labelgrid.add_widget(box, row=0, col=1)\nbox_widget.width_max = 90\nbox_widget.height_max = 120\n\nbottom_spacer = vp.Widget()\nlabelgrid.add_widget(bottom_spacer, row=1, col=0)\n\nlabels = [vp.Label('n=%d' % plot_nvals[i], color=colors[i], anchor_x='left')\n for i in range(len(plot_nvals))]\nboxgrid = box.add_grid()\nfor i, label in enumerate(labels):\n label_widget = boxgrid.add_widget(label, row=i, col=0)\n\n\ngrid = vp.visuals.GridLines(color=(0, 0, 0, 0.5))\ngrid.set_gl_state('translucent')\nfig[0, 0].view.add(grid)\n\n\nif __name__ == '__main__':\n fig.show(run=True)" ] } ], "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 }