{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "1b6f6b11-0fbb-453f-a1d0-2913af2550cf", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "eadd3346-207e-40f1-b8fb-e08fc44190af", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "23fa5918-f383-4f09-8f5a-ed0e1d5e4d85", "metadata": {}, "outputs": [], "source": [ "# Define the functions\n", "def f1(x):\n", " return np.sin(3*x) / (x * (np.cos(x) + 2))\n", "\n", "def f2(x):\n", " return np.cos(x) / x\n", "\n", "def f3(x):\n", " return np.exp(-x)\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "4348460a-eb92-494b-9020-5c6fd4499b31", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = ['#FFB6C1', '#AAFFAA', '#ADD8E6']\n", "p = (ggplot()\n", " + geom_vline(xintercept=0, size=0.4) \n", " + geom_hline(yintercept=0, size=0.4) \n", " + geom_function(fun=f1, xlim=[0.1, 12], color=c[0], size=2, \n", " n=300, manual_key=layer_key(' sin(3x) \\n--------\\n x(cos(x) + 2)', size=3))\n", " # n=300, manual_key=layer_key(' sin(3x)', size=3))\n", " + geom_function(fun=f2, xlim=[0.1, 12], color=c[1], \n", " n=300, manual_key=layer_key('cos(x) / x', size=3))\n", " + geom_function(fun=f3, xlim=[0.1, 12], color=c[2], \n", " n=300, manual_key=layer_key('\\( e^{-x} \\)', size=3))\n", " + scale_x_continuous(expand=[0, 0.2])\n", " + scale_y_continuous(limits=[-0.4, 1.0])\n", " + labs(\n", " x='x',\n", " y='f(x)',\n", " title='Mathematical Functions'\n", " )\n", " + theme_classic()\n", " \n", " + theme(\n", " # Titles, labels\n", " text=element_text(face='italic', family='Computer Modern'), \n", " plot_title=element_text(size=20, hjust=0.05),\n", " axis_title=element_text(size=18),\n", " legend_text=element_text(size=18, vjust=0.5),\n", " # Legend\n", " legend_background=element_rect(size=1),\n", " legend_position=[0.95, 0.9], \n", " legend_justification=[1, 1],\n", " # Axis, gridlines \n", " axis_line='blank', axis_ticks='blank',\n", " panel_grid_major=element_line(linetype='longdash'),\n", " )\n", " + theme(\n", " # Layout improvements\n", " panel_inset=4,\n", " plot_inset=0,\n", " axis_text=element_text(margin=0),\n", " axis_title=element_text(margin=0),\n", " plot_margin=16\n", " )\n", " \n", " + flavor_solarized_dark() \n", " + ggsize(900, 500) \n", ") \n", "\n", "p" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.21" } }, "nbformat": 4, "nbformat_minor": 5 }