{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Tutorial 4" ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "\"\"\"\n", "Tutorial 4.\n", "\n", "Add raw tikz code to the tikz subplot.\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "from maxplotlib import Canvas" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "c = Canvas(width=800, ratio=0.5)\n", "tikz = c.add_tikzfigure(grid=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "# Add nodes\n", "tikz.add_node(0, 0, \"A\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n", "tikz.add_node(10, 0, \"B\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n", "tikz.add_node(10, 10, \"C\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n", "tikz.add_node(0, 10, \"D\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=2)" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "# Add a line between nodes\n", "tikz.add_path(\n", " [\"A\", \"B\", \"C\", \"D\"],\n", " path_actions=[\"draw\", \"rounded corners\"],\n", " fill=\"red\",\n", " opacity=0.5,\n", " cycle=True,\n", " layer=1,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "raw_tikz = r\"\"\"\n", "\\foreach \\i in {0, 45, 90, 135, 180, 225, 270, 315} {\n", " % Place a node at angle \\i\n", " \\node[circle, draw, fill=green] at (\\i:3) (N\\i) {};\n", "}\n", "\n", "% Draw lines connecting the nodes\n", "\\foreach \\i/\\j in {0/45, 45/90, 90/135, 135/180, 180/225, 225/270, 270/315, 315/0} {\n", " \\draw (N\\i) -- (N\\j);\n", "}\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "tikz.add_raw(raw_tikz)" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "tikz.add_node(0.5, 0.5, content=\"Cube\", layer=10)" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "# Generate the TikZ script\n", "script = tikz.generate_tikz()\n", "print(script)\n", "# print(tikz.generate_standalone())\n", "# tikz.compile_pdf(\"tutorial_04_01.pdf\")\n", "#" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" }, "kernelspec": { "display_name": "env_maxplotlib", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }