{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plot lines using showlines\n\nCompute numerical integrals using :func:`Var.integrate` and use :func:`showlines` to make plot \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pygeode as pyg, numpy as np\nimport pylab as pyl\n\n# Use longitudes as horizontal axis\nx = pyg.regularlon(45)\n\nlam = np.pi * x / 180.\n\npyl.ioff()\n\n# Example 1: f = sin(x)\n# F = int_0^x f dx' = 1 - cos(x)\n# Different integration methods\n\nf = pyg.sin(lam)\n\nFr = f.integrate('lon', dx = lam, type='rectr')\nFl = f.integrate('lon', dx = lam, type='rectl')\nFt = f.integrate('lon', dx = lam, type='trapz')\n\nax1 = pyg.showlines([1 - pyg.cosd(x), Fr, Fl, Ft], \n fmts = ['k+', '_', '_', 'x'], \n labels = [r'$1 - \\cos x$', 'rectr', 'rectl', 'trapz'], fig=3)\n\n# Set panel title and axes labels\nax1.setp(title = r\"$\\int_0^x \\sin(x') dx'$\", ylabel = '')\n# Adjust size and axis padding\nax1.size = (4.1, 3)\nax1.pad = [0.5, 0.3, 0.1, 0.4]\n\n# Example 2: f = cos(x)\n# Different integration directions\n\nf = pyg.cos(lam)\n\nFf = f.integrate('lon', dx = lam, order=1)\nFb = f.integrate('lon', dx = lam, order=-1)\n\nax2 = pyg.showlines([f, Ff, Fb], \n fmts = ['k', '+', 'x'], \n labels = [r'$\\cos x$', 'order = 1', 'order = -1'], fig=3)\n\n# Set panel title and axes labels\nax2.setp(title = r\"$\\int_0^x \\cos x' dx'$, $\\int_{2\\pi}^x \\cos x' dx'$\", ylabel = '')\n# Adjust size and axis padding\nax2.size = (4.1, 3)\nax2.pad = [0.5, 0.3, 0.1, 0.4]\n\nax = pyg.plot.grid([[ax1], [ax2]])\npyl.ion()\n\nax.render()" ] } ], "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.12" } }, "nbformat": 4, "nbformat_minor": 0 }