{ "cells": [ { "cell_type": "raw", "id": "b6b9aa5c-59ce-463d-acc4-212be8474b87", "metadata": {}, "source": [ "---\n", "title: \"Quarto Computations\"\n", "jupyter: python3\n", "---" ] }, { "cell_type": "markdown", "id": "c22ef656-2dde-4dfd-9f07-fc46136a6cfd", "metadata": {}, "source": [ "## NumPy" ] }, { "cell_type": "code", "execution_count": null, "id": "333178f2-6bbc-48d6-99f4-4e4f6ab020f9", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "a = np.arange(15).reshape(3, 5)\n", "a" ] }, { "cell_type": "markdown", "id": "b55a4508-6810-4434-9113-1734092beeb6", "metadata": {}, "source": [ "## Matplotlib" ] }, { "cell_type": "code", "execution_count": null, "id": "923faf21-dfa9-4b72-8e05-82619a5e7429", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "fig = plt.figure()\n", "x = np.arange(10)\n", "y = 2.5 * np.sin(x / 20 * np.pi)\n", "yerr = np.linspace(0.05, 0.2, 10)\n", "\n", "plt.errorbar(x, y + 3, yerr=yerr, label='both limits (default)')\n", "plt.errorbar(x, y + 2, yerr=yerr, uplims=True, label='uplims=True')\n", "plt.errorbar(x, y + 1, yerr=yerr, uplims=True, lolims=True,\n", " label='uplims=True, lolims=True')\n", "\n", "upperlimits = [True, False] * 5\n", "lowerlimits = [False, True] * 5\n", "plt.errorbar(x, y, yerr=yerr, uplims=upperlimits, lolims=lowerlimits,\n", " label='subsets of uplims and lolims')\n", "\n", "plt.legend(loc='lower right')\n", "plt.show(fig)" ] }, { "cell_type": "markdown", "id": "aa42be5d-498c-43eb-97ae-f5b44391c2a6", "metadata": {}, "source": [ "## Plotly" ] }, { "cell_type": "code", "execution_count": null, "id": "90a852a5-20e9-4597-b55e-23861591693c", "metadata": {}, "outputs": [], "source": [ "import plotly.express as px\n", "import plotly.io as pio\n", "gapminder = px.data.gapminder()\n", "gapminder2007 = gapminder.query(\"year == 2007\")\n", "fig = px.scatter(gapminder2007, \n", " x=\"gdpPercap\", y=\"lifeExp\", color=\"continent\", \n", " size=\"pop\", size_max=60,\n", " hover_name=\"country\")\n", "fig.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.9.5" } }, "nbformat": 4, "nbformat_minor": 5 }