Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
"matplotlib",
"pint",
"plotly",
"tikzpics>=0.1.1",
"tikzfigure>=0.2.0",
]
[project.optional-dependencies]
test = [
Expand Down
16 changes: 8 additions & 8 deletions src/maxplotlib/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import matplotlib.patches as patches
import matplotlib.pyplot as plt
from plotly.subplots import make_subplots
from tikzpics import TikzFigure
from tikzfigure import TikzFigure

from maxplotlib.backends.matplotlib.utils import (
set_size,
Expand Down Expand Up @@ -415,8 +415,8 @@ def plot(
)
elif backend == "plotly":
return self.plot_plotly(savefig=savefig)
elif backend == "tikzpics":
return self.plot_tikzpics(savefig=savefig)
elif backend == "tikzfigure":
return self.plot_tikzfigure(savefig=savefig)
else:
raise ValueError(f"Invalid backend: {backend}")

Expand All @@ -438,8 +438,8 @@ def show(
# self._matplotlib_fig.show()
elif backend == "plotly":
self.plot_plotly(savefig=False)
elif backend == "tikzpics":
fig = self.plot_tikzpics(savefig=False, verbose=verbose)
elif backend == "tikzfigure":
fig = self.plot_tikzfigure(savefig=False, verbose=verbose)
fig.show()
else:
raise ValueError("Invalid backend")
Expand Down Expand Up @@ -507,20 +507,20 @@ def plot_matplotlib(
self._matplotlib_axes = axes
return fig, axes

def plot_tikzpics(
def plot_tikzfigure(
self,
savefig: str | None = None,
verbose: bool = False,
) -> TikzFigure:
if len(self.subplots) > 1:
raise NotImplementedError(
"Only one subplot is supported for tikzpics backend."
"Only one subplot is supported for tikzfigure backend."
)
for (row, col), line_plot in self.subplots.items():
if verbose:
print(f"Plotting subplot at row {row}, col {col}")
print(f"{line_plot = }")
tikz_subplot = line_plot.plot_tikzpics(verbose=verbose)
tikz_subplot = line_plot.plot_tikzfigure(verbose=verbose)
return tikz_subplot

def plot_plotly(self, show=True, savefig=None, usetex=False):
Expand Down
4 changes: 2 additions & 2 deletions src/maxplotlib/subfigure/line_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import plotly.graph_objects as go
from mpl_toolkits.axes_grid1 import make_axes_locatable
from tikzpics import TikzFigure
from tikzfigure import TikzFigure


class Node:
Expand Down Expand Up @@ -221,7 +221,7 @@ def plot_matplotlib(
if self.ymax is not None:
ax.axis(ymax=self.ymax)

def plot_tikzpics(self, layers=None, verbose: bool = False) -> TikzFigure:
def plot_tikzfigure(self, layers=None, verbose: bool = False) -> TikzFigure:

tikz_figure = TikzFigure()
for layer_name, layer_lines in self.layered_line_data.items():
Expand Down
2 changes: 1 addition & 1 deletion src/maxplotlib/utils/options.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Literal

Backends = Literal["matplotlib", "plotly", "tikzpics"]
Backends = Literal["matplotlib", "plotly", "tikzfigure"]
119 changes: 14 additions & 105 deletions tutorials/tutorial_04.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'\\nTutorial 4.\\n\\nAdd raw tikz code to the tikz subplot.\\n'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"\"\"\"\n",
"Tutorial 4.\n",
Expand All @@ -35,7 +24,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
Expand All @@ -45,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
Expand All @@ -56,23 +45,12 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "4",
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [
{
"data": {
"text/plain": [
"<tikzpics.node.Node at 0x10ce7b5c0>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Add nodes\n",
"tikz.add_node(0, 0, label=\"A\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n",
Expand All @@ -83,21 +61,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<tikzpics.path.Path at 0x113e4d940>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Add a line between nodes\n",
"tikz.draw(\n",
Expand All @@ -112,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
Expand All @@ -132,32 +99,21 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"# TODO: Not implemented in tikzpics yet\n",
"# TODO: Not implemented in tikzfigure yet\n",
"# tikz.add_raw(raw_tikz)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<tikzpics.node.Node at 0x113ecba80>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"tikz.add_node(0.5, 0.5, content=\"Cube\", layer=10)"
]
Expand All @@ -167,54 +123,7 @@
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"\n",
"\n",
"% --------------------------------------------- %\n",
"% Tikzfigure generated by tikzpics v0.1.1 %\n",
"% https://github.com/max-models/tikzpics %\n",
"% --------------------------------------------- %\n",
"\\begin{tikzpicture}\n",
" \n",
" % Define the layers library\n",
" \\pgfdeclarelayer{0}\n",
" \\pgfdeclarelayer{1}\n",
" \\pgfdeclarelayer{10}\n",
" \\pgfdeclarelayer{2}\n",
" \\pgfsetlayers{0,1,10,2}\n",
" \n",
" % Layer 0\n",
" \\begin{pgfonlayer}{0}\n",
" \\node[shape=circle, draw=black, fill=blue] (A) at (0, 0) {};\n",
" \\node[shape=circle, draw=black, fill=blue] (B) at (10, 0) {};\n",
" \\node[shape=circle, draw=black, fill=blue] (C) at (10, 10) {};\n",
" \\end{pgfonlayer}{0}\n",
" \n",
" % Layer 2\n",
" \\begin{pgfonlayer}{2}\n",
" \\node[shape=circle, draw=black, fill=blue] (D) at (0, 10) {};\n",
" \\end{pgfonlayer}{2}\n",
" \n",
" % Layer 1\n",
" \\begin{pgfonlayer}{1}\n",
" \\draw[path actions=['draw', 'rounded corners'], fill=red, opacity=0.5] (A) to (B) to (C) to (D) -- cycle;\n",
" \\end{pgfonlayer}{1}\n",
" \n",
" % Layer 10\n",
" \\begin{pgfonlayer}{10}\n",
" \\node (node4) at (0.5, 0.5) {Cube};\n",
" \\end{pgfonlayer}{10}\n",
"\\end{tikzpicture}\n",
"\n"
]
}
],
"outputs": [],
"source": [
"# Generate the TikZ script\n",
"script = tikz.generate_tikz()\n",
Expand Down
2 changes: 1 addition & 1 deletion tutorials/tutorial_07_tikzpics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"\n",
"\n",
"# TODO: Uncomment if pdflatex is installed\n",
"# c.show(backend=\"tikzpics\")"
"# c.show(backend=\"tikzfigure\")"
]
}
],
Expand Down
Loading