{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Tutorial 3" ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "from tikzpics import TikzFigure" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "fig = TikzFigure()\n", "\n", "num_xpoints = 5\n", "num_ypoints = 3\n", "dx = 2.5\n", "\n", "origin = fig.add_node(\n", " ((num_xpoints - 1) / 2) * dx,\n", " -2.5,\n", " label=\"origin\",\n", " content=r\"\\color{white}O\",\n", " shape=\"circle\",\n", " fill=\"red\",\n", " comment=\"Origin node\",\n", ")\n", "\n", "# Green nodes at the bottom\n", "with fig.add_loop(\"i\", range(num_xpoints), comment=\"Green nodes at the bottom\") as loop:\n", " node = loop.add_node(\n", " f\"{dx}*\\\\i\",\n", " -5.0,\n", " label=r\"xnodes\\i\",\n", " content=r\"\\color{white}\\i\",\n", " shape=\"circle\",\n", " fill=\"green!50!black\",\n", " )\n", "\n", "# Draw lines from origin to the bottom nodes\n", "with fig.add_loop(\n", " \"i\", range(num_xpoints), comment=\"Lines from origin to green nodes\"\n", ") as loop:\n", " loop.add_path(\n", " [origin, node],\n", " color=\"black\",\n", " options=[\"line width=2\"],\n", " )\n", "\n", "# Draw the top node grid\n", "with fig.add_loop(\"i\", range(num_xpoints), comment=\"Blue nodegrid\") as loop_i:\n", " with loop_i.add_loop(\"j\", range(num_ypoints), comment=\"inner j-loop\") as loop_j:\n", " node = loop_j.add_node(\n", " f\"{dx}*\\\\i\",\n", " r\"3*\\j\",\n", " label=r\"xynodes\\i\\j\",\n", " content=r\"\\color{white}\\i,\\j\",\n", " shape=\"circle\",\n", " fill=\"blue\",\n", " )\n", "\n", "# Lines from origin to blue node grid\n", "with fig.add_loop(\n", " \"i\", range(num_xpoints), comment=\"Lines from origin to blue node grid\"\n", ") as loop_i:\n", " with loop_i.add_loop(\"j\", range(num_ypoints), comment=\"inner j-loop\") as loop_j:\n", " loop_j.add_path(\n", " [origin, node],\n", " color=\"black\",\n", " options=[\"line width=3\"],\n", " )\n", "\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "print(fig.generate_standalone())" ] } ], "metadata": { "kernelspec": { "display_name": "env_tikzpics", "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.3" } }, "nbformat": 4, "nbformat_minor": 5 }