{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Unit handling\n\nThe example below shows support for unit conversions over masked\narrays.\n\n.. only:: builder_html\n\n This example requires :download:`basic_units.py `\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from basic_units import hertz, minutes, secs\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n# create masked array\ndata = (1, 2, 3, 4, 5, 6, 7, 8)\nmask = (1, 0, 1, 0, 0, 0, 1, 0)\nxsecs = secs * np.ma.MaskedArray(data, mask, float)\n\nfig, (ax1, ax2, ax3) = plt.subplots(nrows=3, sharex=True)\n\nax1.scatter(xsecs, xsecs)\nax1.yaxis.set_units(secs)\nax2.scatter(xsecs, xsecs, yunits=hertz)\nax3.scatter(xsecs, xsecs, yunits=minutes)\n\nfig.tight_layout()\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.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }