{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Streamplot\n\nDemo of the ``streamplot`` function.\n\nA streamplot, or streamline plot, is used to display 2D vector fields. This\nexample shows a few features of the stream plot function:\n\n* Varying the color along a streamline.\n* Varying the density of streamlines.\n* Varying the line width along a stream line.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport matplotlib.pyplot as plt\n\nY, X = np.mgrid[-3:3:100j, -3:3:100j]\nU = -1 - X ** 2 + Y\nV = 1 + X - Y ** 2\nspeed = np.sqrt(U * U + V * V)\n\nplt.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn)\nplt.colorbar()\n\nf, (ax1, ax2) = plt.subplots(ncols=2)\nax1.streamplot(X, Y, U, V, density=[0.5, 1])\n\nlw = 5 * speed / speed.max()\nax2.streamplot(X, Y, U, V, density=0.6, color=\"k\", linewidth=lw)\n\nplt.show()" ] } ], "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.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }