diff --git a/src/maxplotlib/__init__.py b/src/maxplotlib/__init__.py new file mode 100644 index 0000000..5f86d34 --- /dev/null +++ b/src/maxplotlib/__init__.py @@ -0,0 +1,3 @@ +from maxplotlib.canvas.canvas import Canvas + +__all__ = ["Canvas"] diff --git a/src/maxplotlib/backends/matplotlib/utils_old.py b/src/maxplotlib/backends/matplotlib/utils_old.py index 25abfdc..2516ab6 100644 --- a/src/maxplotlib/backends/matplotlib/utils_old.py +++ b/src/maxplotlib/backends/matplotlib/utils_old.py @@ -299,7 +299,12 @@ def setup_plotstyle( def set_common_xlabel(self, xlabel="common X"): self.fig.text( - 0.5, -0.075, xlabel, va="center", ha="center", fontsize=self.fontsize + 0.5, + -0.075, + xlabel, + va="center", + ha="center", + fontsize=self.fontsize, ) # fig.text(0.04, 0.5, 'common Y', va='center', ha='center', rotation='vertical', fontsize=rcParams['axes.labelsize']) @@ -438,7 +443,9 @@ def scale_axis( i0 = int(xmin / delta) i1 = int(xmax / delta + 1) locs = np.arange( - includepoint - width, includepoint + width + delta, delta + includepoint - width, + includepoint + width + delta, + delta, ) locs = locs[locs >= xmin - 1e-12] locs = locs[locs <= xmax + 1e-12] @@ -473,7 +480,9 @@ def scale_axis( i0 = int(ymin / delta) i1 = int(ymax / delta + 1) locs = np.arange( - includepoint - width, includepoint + width + delta, delta + includepoint - width, + includepoint + width + delta, + delta, ) locs = locs[locs >= ymin - 1e-12] locs = locs[locs <= ymax + 1e-12] @@ -507,7 +516,10 @@ def adjustFigAspect(self, aspect=1): else: ylim /= aspect self.fig.subplots_adjust( - left=0.5 - xlim, right=0.5 + xlim, bottom=0.5 - ylim, top=0.5 + ylim + left=0.5 - xlim, + right=0.5 + xlim, + bottom=0.5 - ylim, + top=0.5 + ylim, ) def add_figure_label( @@ -619,14 +631,16 @@ def savefig( # self.fig.savefig(self.directory + filename + '.' + format,bbox_inches='tight', transparent=False) if tight_layout: self.fig.savefig( - self.directory + filename + "." + format, bbox_inches="tight" + self.directory + filename + "." + format, + bbox_inches="tight", ) else: self.fig.savefig(self.directory + filename + "." + format) elif format == "pgf": # Save pgf figure self.fig.savefig( - self.directory + filename + "." + format, bbox_inches="tight" + self.directory + filename + "." + format, + bbox_inches="tight", ) # Replace pgf figure colors with colorlet @@ -672,7 +686,8 @@ def savefig( else: try: plt.savefig( - self.directory + filename + "." + format, bbox_inches="tight" + self.directory + filename + "." + format, + bbox_inches="tight", ) except Exception as e: print( @@ -680,7 +695,7 @@ def savefig( + self.directory + filename + "." - + format + + format, ) print(e) @@ -690,7 +705,7 @@ def savefig( for format in formats: if format in imgcat_formats: f.write( - "imgcat " + self.directory + filename + "." + format + "\n" + "imgcat " + self.directory + filename + "." + format + "\n", ) if print_imgcat and ("png" in formats or "pdf" in formats): diff --git a/src/maxplotlib/canvas/canvas.py b/src/maxplotlib/canvas/canvas.py index 0885184..0e6faaf 100644 --- a/src/maxplotlib/canvas/canvas.py +++ b/src/maxplotlib/canvas/canvas.py @@ -5,8 +5,8 @@ from plotly.subplots import make_subplots import maxplotlib.backends.matplotlib.utils as plt_utils -import maxplotlib.subfigure.line_plot as lp -import maxplotlib.subfigure.tikz_figure as tf +from maxplotlib.subfigure.line_plot import LinePlot +from maxplotlib.subfigure.tikz_figure import TikzFigure class Canvas: @@ -37,11 +37,15 @@ def __init__(self, **kwargs): # Dictionary to store lines for each subplot # Key: (row, col), Value: list of lines with their data and kwargs - self.subplots = {} + self._subplots = {} self._num_subplots = 0 self._subplot_matrix = [[None] * self.ncols for _ in range(self.nrows)] + @property + def subplots(self): + return self._subplots + @property def layers(self): layers = [] @@ -66,34 +70,92 @@ def generate_new_rowcol(self, row, col): assert col is not None, "Not enough columns!" return row, col - def add_tikzfigure(self, **kwargs): + def add_line( + self, + x_data, + y_data, + layer=0, + subplot: LinePlot | None = None, + row: int | None = None, + col: int | None = None, + plot_type="plot", + **kwargs, + ): + if row is not None and col is not None: + try: + subplot = self._subplot_matrix[row][col] + except KeyError: + raise ValueError("Invalid subplot position.") + else: + row, col = 0, 0 + subplot = self._subplot_matrix[row][col] + + if subplot is None: + row, col = self.generate_new_rowcol(row, col) + subplot = self.add_subplot(col=col, row=row) + + subplot.add_line( + x_data=x_data, + y_data=y_data, + layer=layer, + plot_type=plot_type, + **kwargs, + ) + + def add_tikzfigure( + self, + col=None, + row=None, + label=None, + **kwargs, + ): """ Adds a subplot to the figure. Parameters: **kwargs: Arbitrary keyword arguments. - - col (int): Column index for the subplot. - - row (int): Row index for the subplot. - - label (str): Label to identify the subplot. """ - col = kwargs.get("col", None) - row = kwargs.get("row", None) - label = kwargs.get("label", None) row, col = self.generate_new_rowcol(row, col) # Initialize the LinePlot for the given subplot position - tikz_figure = tf.TikzFigure(**kwargs) + tikz_figure = TikzFigure( + col=col, + row=row, + label=label, + **kwargs, + ) self._subplot_matrix[row][col] = tikz_figure # Store the LinePlot instance by its position for easy access if label is None: - self.subplots[(row, col)] = tikz_figure + self._subplots[(row, col)] = tikz_figure else: - self.subplots[label] = tikz_figure + self._subplots[label] = tikz_figure return tikz_figure - def add_subplot(self, **kwargs): + def add_subplot( + self, + col: int | None = None, + row: int | None = None, + figsize: tuple = (10, 6), + title: str | None = None, + caption: str | None = None, + description: str | None = None, + label: str | None = None, + grid: bool = False, + legend: bool = False, + xmin: float | int | None = None, + xmax: float | int | None = None, + ymin: float | int | None = None, + ymax: float | int | None = None, + xlabel: str | None = None, + ylabel: str | None = None, + xscale: float | int = 1.0, + yscale: float | int = 1.0, + xshift: float | int = 0.0, + yshift: float | int = 0.0, + ): """ Adds a subplot to the figure. @@ -103,21 +165,32 @@ def add_subplot(self, **kwargs): - row (int): Row index for the subplot. - label (str): Label to identify the subplot. """ - col = kwargs.get("col", None) - row = kwargs.get("row", None) - label = kwargs.get("label", None) row, col = self.generate_new_rowcol(row, col) # Initialize the LinePlot for the given subplot position - line_plot = lp.LinePlot(**kwargs) + line_plot = LinePlot( + title=title, + grid=grid, + legend=legend, + xmin=xmin, + xmax=xmax, + ymin=ymin, + ymax=ymax, + xlabel=xlabel, + ylabel=ylabel, + xscale=xscale, + yscale=yscale, + xshift=xshift, + yshift=yshift, + ) self._subplot_matrix[row][col] = line_plot # Store the LinePlot instance by its position for easy access if label is None: - self.subplots[(row, col)] = line_plot + self._subplots[(row, col)] = line_plot else: - self.subplots[label] = line_plot + self._subplots[label] = line_plot return line_plot def savefig( @@ -136,7 +209,10 @@ def savefig( for layer in self.layers: layers.append(layer) fig, axs = self.plot( - show=False, backend="matplotlib", savefig=True, layers=layers + show=False, + backend="matplotlib", + savefig=True, + layers=layers, ) _fn = f"{filename_no_extension}_{layers}.{extension}" fig.savefig(_fn) @@ -153,25 +229,38 @@ def savefig( else: fig, axs = self.plot( - show=False, backend="matplotlib", savefig=True, layers=layers + show=False, + backend="matplotlib", + savefig=True, + layers=layers, ) fig.savefig(full_filepath) if verbose: print(f"Saved {full_filepath}") - def plot(self, backend="matplotlib", show=True, savefig=False, layers=None): + def plot(self, backend="matplotlib", savefig=False, layers=None): if backend == "matplotlib": - return self.plot_matplotlib(show=show, savefig=savefig, layers=layers) + return self.plot_matplotlib(savefig=savefig, layers=layers) elif backend == "plotly": - self.plot_plotly(show=show, savefig=savefig) + return self.plot_plotly(savefig=savefig) + else: + raise ValueError(f"Invalid backend: {backend}") - def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False): + def show(self, backend="matplotlib"): + if backend == "matplotlib": + self.plot(backend="matplotlib", savefig=False, layers=None) + self._matplotlib_fig.show() + elif backend == "plotly": + plot = self.plot_plotly(savefig=False) + else: + raise ValueError("Invalid backend") + + def plot_matplotlib(self, savefig=False, layers=None, usetex=False): """ Generate and optionally display the subplots. Parameters: filename (str, optional): Filename to save the figure. - show (bool): Whether to display the plot. """ tex_fonts = plt_utils.setup_tex_fonts(fontsize=self.fontsize, usetex=usetex) @@ -205,17 +294,11 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False): for (row, col), subplot in self.subplots.items(): ax = axes[row][col] - # print(f"{subplot = }") subplot.plot_matplotlib(ax, layers=layers) # ax.set_title(f"Subplot ({row}, {col})") ax.grid() - # Set caption, labels, etc., if needed - # plt.tight_layout() - if show: - plt.show() - # else: - # plt.close() + # Set caption, labels, etc., if needed self._plotted = True self._matplotlib_fig = fig self._matplotlib_axes = axes @@ -240,7 +323,8 @@ def plot_plotly(self, show=True, savefig=None, usetex=False): fig_width, fig_height = self._figsize else: fig_width, fig_height = plt_utils.set_size( - width=self._width, ratio=self._ratio + width=self._width, + ratio=self._ratio, ) # print(self._width, fig_width, fig_height) # Create subplots @@ -271,8 +355,8 @@ def plot_plotly(self, show=True, savefig=None, usetex=False): fig.write_image(savefig) # Show or return the figure - if show: - fig.show() + # if show: + # fig.show() return fig # Property getters diff --git a/src/maxplotlib/subfigure/line_plot.py b/src/maxplotlib/subfigure/line_plot.py index dcea414..e1daf44 100644 --- a/src/maxplotlib/subfigure/line_plot.py +++ b/src/maxplotlib/subfigure/line_plot.py @@ -19,7 +19,13 @@ def __init__(self, x, y, label="", content="", layer=0, **kwargs): class Path: def __init__( - self, nodes, path_actions=[], cycle=False, label="", layer=0, **kwargs + self, + nodes, + path_actions=[], + cycle=False, + label="", + layer=0, + **kwargs, ): self.nodes = nodes self.path_actions = path_actions @@ -30,34 +36,52 @@ def __init__( class LinePlot: - def __init__(self, **kwargs): + def __init__( + self, + title: str | None = None, + grid: bool = False, + legend: bool = False, + xmin: float | int | None = None, + xmax: float | int | None = None, + ymin: float | int | None = None, + ymax: float | int | None = None, + xlabel: str | None = None, + ylabel: str | None = None, + xscale: float | int = 1.0, + yscale: float | int = 1.0, + xshift: float | int = 0.0, + yshift: float | int = 0.0, + ): """ Initialize the LinePlot class for a subplot. Parameters: - **kwargs: Arbitrary keyword arguments. - - figsize (tuple): Figure size (default is (10, 6)). - - caption (str): Caption for the plot. - - description (str): Description of the plot. - - label (str): Label for the plot. - - grid (bool): Whether to display grid lines (default is False). - TODO: Add all options + title (str): Title of the plot. + caption (str): Caption for the plot. + description (str): Description of the plot. + label (str): Label for the plot. + grid (bool): Whether to display grid lines (default is False). + legend (bool): Whether to display legend (default is False). + xmin, xmax, ymin, ymax (float): Axis limits. + xlabel, ylabel (str): Axis labels. + xscale, yscale (float): Scaling factors for axes. + xshift, yshift (float): Shifts for axes. """ - # Set default values - self._figsize = kwargs.get("figsize", (10, 6)) - self._title = kwargs.get("title", None) - self._caption = kwargs.get("caption", None) - self._description = kwargs.get("description", None) - self._label = kwargs.get("label", None) - self._grid = kwargs.get("grid", False) - self._legend = kwargs.get("legend", False) - self._xmin = kwargs.get("xmin", None) - self._xmax = kwargs.get("xmax", None) - self._ymin = kwargs.get("ymin", None) - self._ymax = kwargs.get("ymax", None) - - self._xlabel = kwargs.get("xlabel", None) - self._ylabel = kwargs.get("ylabel", None) + + self._title = title + self._grid = grid + self._legend = legend + self._xmin = xmin + self._xmax = xmax + self._ymin = ymin + self._ymax = ymax + self._xlabel = xlabel + self._ylabel = ylabel + self._xscale = xscale + self._yscale = yscale + self._xshift = xshift + self._yshift = yshift + # List to store line data, each entry contains x and y data, label, and plot kwargs self.line_data = [] self.layered_line_data = {} @@ -65,17 +89,10 @@ def __init__(self, **kwargs): # Initialize lists to hold Node and Path objects self.nodes = [] self.paths = [] - # self.layers = {} # Counter for unnamed nodes self._node_counter = 0 - # Scaling - self._xscale = kwargs.get("xscale", 1.0) - self._yscale = kwargs.get("yscale", 1.0) - self._xshift = kwargs.get("xshift", 0.0) - self._yshift = kwargs.get("yshift", 0.0) - def add_caption(self, caption): self._caption = caption @@ -86,7 +103,14 @@ def _add(self, obj, layer): else: self.layered_line_data[layer] = [obj] - def add_line(self, x_data, y_data, layer=0, plot_type="plot", **kwargs): + def add_line( + self, + x_data, + y_data, + layer=0, + plot_type="plot", + **kwargs, + ): """ Add a line to the plot. @@ -178,8 +202,6 @@ def plot_matplotlib(self, ax, layers=None): plt.colorbar(im, cax=cax, label="Potential (V)") if self._title: ax.set_title(self._title) - if self._label: - ax.set_ylabel(self._label) if self._xlabel: ax.set_xlabel(self._xlabel) if self._ylabel: @@ -219,7 +241,8 @@ def plot_plotly(self): line=dict( color=line["kwargs"].get("color", None), dash=linestyle_map.get( - line["kwargs"].get("linestyle", "solid"), "solid" + line["kwargs"].get("linestyle", "solid"), + "solid", ), ), ) @@ -305,42 +328,6 @@ def ymin(self): def ymax(self): return self._ymax - # Getter and Setter for figsize - @property - def figsize(self): - return self._figsize - - @figsize.setter - def figsize(self, value): - self._figsize = value - - # Getter and Setter for caption - @property - def caption(self): - return self._caption - - @caption.setter - def caption(self, value): - self._caption = value - - # Getter and Setter for description - @property - def description(self): - return self._description - - @description.setter - def description(self, value): - self._description = value - - # Getter and Setter for label - @property - def label(self): - return self._label - - @label.setter - def label(self, value): - self._label = value - # Getter and Setter for grid @property def grid(self): diff --git a/src/maxplotlib/subfigure/tikz_figure.py b/src/maxplotlib/subfigure/tikz_figure.py index 7d1a08a..4751c51 100644 --- a/src/maxplotlib/subfigure/tikz_figure.py +++ b/src/maxplotlib/subfigure/tikz_figure.py @@ -84,7 +84,13 @@ def to_tikz(self): class Path: def __init__( - self, nodes, path_actions=[], cycle=False, label="", layer=0, **kwargs + self, + nodes, + path_actions=[], + cycle=False, + label="", + layer=0, + **kwargs, ): """ Represents a path (line) connecting multiple nodes. @@ -388,7 +394,7 @@ def plot_matplotlib(self, ax, layers=None): line_width = float(match.group(1)) else: print( - f"Invalid line width specification: '{line_width_spec}', defaulting to 1" + f"Invalid line width specification: '{line_width_spec}', defaulting to 1", ) line_width = 1 else: diff --git a/tutorials/tutorial_01.ipynb b/tutorials/tutorial_01.ipynb index 77360d9..53d144f 100644 --- a/tutorials/tutorial_01.ipynb +++ b/tutorials/tutorial_01.ipynb @@ -16,7 +16,7 @@ "metadata": {}, "outputs": [], "source": [ - "import maxplotlib.canvas.canvas as canvas\n", + "from maxplotlib import Canvas\n", "\n", "%load_ext autoreload\n", "%autoreload 2" @@ -29,24 +29,41 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=\"17cm\", ratio=0.5, fontsize=12)\n", + "c = Canvas(width=\"17cm\", ratio=0.5, fontsize=12)\n", + "c.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\")\n", + "c.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n", + "c.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3", + "metadata": {}, + "outputs": [], + "source": [ + "# You can also explicitly create a subplot and add lines to it\n", + "\n", + "c = Canvas(width=\"17cm\", ratio=0.5, fontsize=12)\n", "sp = c.add_subplot(\n", " grid=True, xlabel=\"(x - 10) * 0.1\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n", ")\n", + "\n", "sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\")\n", "sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n", - "c.plot()\n", - "c.savefig(filename=\"tutorial_01_01.pdf\")" + "c.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "3", + "id": "4", "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=\"17cm\", ncols=2, nrows=2, ratio=0.5)\n", + "# Example with multiple subplots\n", + "\n", + "c = Canvas(width=\"17cm\", ncols=2, nrows=2, ratio=0.5)\n", "sp = c.add_subplot(grid=True)\n", "c.add_subplot(row=1)\n", "sp2 = c.add_subplot(row=1, legend=False)\n", @@ -54,28 +71,24 @@ "sp2.add_line(\n", " [0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\"\n", ")\n", - "c.plot(backend=\"matplotlib\")\n", - "c.plot(backend=\"plotly\")\n", - "c.savefig(filename=\"tutorial_01_02.pdf\")" + "c.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "4", + "id": "5", "metadata": {}, "outputs": [], "source": [ "# Test with plotly backend\n", - "c = canvas.Canvas(width=\"17cm\", ratio=0.5)\n", + "c = Canvas(width=\"17cm\", ratio=0.5)\n", "sp = c.add_subplot(\n", " grid=True, xlabel=\"x (mm)\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n", ")\n", "sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\", linestyle=\"-.\")\n", "sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n", - "c.plot(backend=\"matplotlib\")\n", - "c.plot(backend=\"plotly\")\n", - "c.savefig(filename=\"tutorial_01_03.pdf\")" + "c.show()" ] } ], @@ -95,7 +108,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.3" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/tutorials/tutorial_02.ipynb b/tutorials/tutorial_02.ipynb index 8674141..62110a4 100644 --- a/tutorials/tutorial_02.ipynb +++ b/tutorials/tutorial_02.ipynb @@ -15,7 +15,7 @@ "metadata": {}, "outputs": [], "source": [ - "import maxplotlib.canvas.canvas as canvas\n", + "from maxplotlib import Canvas\n", "\n", "%load_ext autoreload\n", "%autoreload 2" @@ -28,7 +28,7 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=800, ratio=0.5)\n", + "c = Canvas(width=800, ratio=0.5)\n", "tikz = c.add_tikzfigure(grid=False)\n", "\n", "# Add nodes\n", @@ -61,7 +61,7 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(ncols=2, width=\"20cm\", ratio=0.5)\n", + "c = Canvas(ncols=2, width=\"20cm\", ratio=0.5)\n", "tikz = c.add_tikzfigure(grid=False)\n", "\n", "# Add nodes\n", @@ -111,7 +111,7 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=800, ratio=0.5)\n", + "c = Canvas(width=800, ratio=0.5)\n", "tikz = c.add_tikzfigure(grid=False)\n", "\n", "# Add nodes\n", @@ -146,7 +146,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.3" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/tutorials/tutorial_03.ipynb b/tutorials/tutorial_03.ipynb index e4f577b..a323007 100644 --- a/tutorials/tutorial_03.ipynb +++ b/tutorials/tutorial_03.ipynb @@ -15,7 +15,7 @@ "metadata": {}, "outputs": [], "source": [ - "import maxplotlib.canvas.canvas as canvas" + "from maxplotlib import Canvas" ] }, { @@ -25,7 +25,7 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=\"17cm\", ratio=0.5)\n", + "c = Canvas(width=\"17cm\", ratio=0.5)\n", "sp = c.add_subplot(\n", " grid=False, xlabel=\"(x - 10) * 0.1\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n", ")\n", @@ -33,8 +33,7 @@ "sp.add_line(\n", " [0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\", layer=1\n", ")\n", - "# c.plot()\n", - "c.savefig(layer_by_layer=True, filename=\"tutorial_03_01.pdf\")" + "c.show()" ] } ], @@ -59,7 +58,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.3" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/tutorials/tutorial_04.ipynb b/tutorials/tutorial_04.ipynb index 964cf55..bf46f10 100644 --- a/tutorials/tutorial_04.ipynb +++ b/tutorials/tutorial_04.ipynb @@ -29,7 +29,7 @@ "metadata": {}, "outputs": [], "source": [ - "import maxplotlib.canvas.canvas as canvas" + "from maxplotlib import Canvas" ] }, { @@ -39,7 +39,7 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=800, ratio=0.5)\n", + "c = Canvas(width=800, ratio=0.5)\n", "tikz = c.add_tikzfigure(grid=False)" ] }, @@ -154,7 +154,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.3" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/tutorials/tutorial_05.ipynb b/tutorials/tutorial_05.ipynb index 959e4ba..55334f8 100644 --- a/tutorials/tutorial_05.ipynb +++ b/tutorials/tutorial_05.ipynb @@ -17,7 +17,7 @@ "source": [ "import numpy as np\n", "\n", - "import maxplotlib.canvas.canvas as canvas\n", + "from maxplotlib import Canvas\n", "\n", "%load_ext autoreload\n", "%autoreload 2" @@ -30,7 +30,7 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=\"17cm\", ratio=0.5)\n", + "c = Canvas(width=\"17cm\", ratio=0.5)\n", "sp = c.add_subplot(grid=True, xlabel=\"x\", ylabel=\"y\")\n", "\n", "# node_a = sp.add_node(\n", @@ -49,17 +49,9 @@ "x = np.arange(0, 2 * np.pi, 0.01)\n", "y = np.sin(x)\n", "sp.add_line(x, y, label=r\"$\\sin(x)$\")\n", - "# c.plot()\n", - "c.savefig(filename=\"tutorial_05_01.pdf\")" + "\n", + "c.show()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -78,7 +70,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.3" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/tutorials/tutorial_06.ipynb b/tutorials/tutorial_06.ipynb index 1278e25..d783520 100644 --- a/tutorials/tutorial_06.ipynb +++ b/tutorials/tutorial_06.ipynb @@ -15,7 +15,7 @@ "metadata": {}, "outputs": [], "source": [ - "import maxplotlib.canvas.canvas as canvas\n", + "from maxplotlib import Canvas\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", @@ -30,13 +30,13 @@ "metadata": {}, "outputs": [], "source": [ - "c = canvas.Canvas(width=\"17cm\", ratio=0.5)\n", + "c = Canvas(width=\"17cm\", ratio=0.5)\n", "sp = c.add_subplot(grid=False, xlabel=\"x\", ylabel=\"y\")\n", "# sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\",layer=1)\n", "data = np.random.random((10, 10))\n", "sp.add_imshow(data, extent=[1, 10, 1, 20], layer=1)\n", - "# c.plot()\n", - "c.savefig(layer_by_layer=True, filename=\"tutorial_06_01.pdf\")" + "\n", + "c.show()" ] }, { @@ -64,7 +64,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.3" + "version": "3.12.3" } }, "nbformat": 4,