diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0d0c7bc..4ddc704 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -27,6 +27,8 @@ jobs: with: apt-packages: "texlive-latex-base texlive-latex-extra texlive-pictures texlive-fonts-recommended lmodern" # stable-branch: main # deploy the latest release at // and devel at //dev/ + # a notebook's outputs are numbered in order: in tutorial 07, 1.html is the Plotly + # preview and 2.png the first compiled TikZ figure smoke-paths: | getting-started/installation/index.html getting-started/quickstart/index.html @@ -35,7 +37,7 @@ jobs: tutorials/tutorial-01/index.html tutorials/tutorial-07-tikz/index.html tutorials/tutorial-17-xarray/index.html - tutorials/tutorial-07-tikz/1.png + tutorials/tutorial-07-tikz/2.png tutorials/tutorial-01/tutorial_01.ipynb api/maxplotlib/index.html api/maxplotlib/canvas/index.html diff --git a/src/maxplotlib/canvas/canvas.py b/src/maxplotlib/canvas/canvas.py index 3079670..c75ae08 100644 --- a/src/maxplotlib/canvas/canvas.py +++ b/src/maxplotlib/canvas/canvas.py @@ -2891,6 +2891,13 @@ def plot_plotly( """ self._validate_import_backend("plotly", allow_unsupported=allow_unsupported) + if any( + isinstance(subplot, TikzFigure) for _, _, subplot in self.iter_subplots() + ): + raise NotImplementedError( + "tikzfigure subplots cannot be rendered with the plotly backend; " + "use the matplotlib or tikzfigure backend" + ) resolved_usetex = self._usetex if usetex is None else usetex for subplot in self._subplot_dict.values(): diff --git a/src/maxplotlib/tests/test_canvas.py b/src/maxplotlib/tests/test_canvas.py index 005e6d6..5379eaa 100644 --- a/src/maxplotlib/tests/test_canvas.py +++ b/src/maxplotlib/tests/test_canvas.py @@ -1378,3 +1378,16 @@ def test_plotly_rendering_keeps_the_global_style(): style = dict(plt.rcParams) canvas.plot_plotly() assert dict(plt.rcParams) == style + + +def test_plotly_refuses_tikzfigure_subplots(): + import pytest + + pytest.importorskip("plotly") + from maxplotlib import Canvas + + canvas = Canvas() + diagram = canvas.add_tikzfigure() + diagram.add_node(0, 0, label="A") + with pytest.raises(NotImplementedError, match="plotly backend"): + canvas.render(backend="plotly") diff --git a/tutorials/tutorial_08_plotly.ipynb b/tutorials/tutorial_08_plotly.ipynb index 2c32b8f..0bc6123 100644 --- a/tutorials/tutorial_08_plotly.ipynb +++ b/tutorials/tutorial_08_plotly.ipynb @@ -383,6 +383,55 @@ "cell_type": "markdown", "id": "20", "metadata": {}, + "source": [ + "### Smaller files and embedding\n", + "\n", + "A standalone file bundles plotly.js, several megabytes. `include_plotlyjs` chooses\n", + "where it comes from: `True` (the default of `savefig`) bundles it, `\"cdn\"` loads it\n", + "from a CDN when the page opens, which keeps the file a few kilobytes but needs a\n", + "network connection, and `False` leaves it out for a page that loads plotly.js itself." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "canvas.savefig(\"figure_bundled.html\", backend=\"plotly\")\n", + "canvas.savefig(\"figure_cdn.html\", backend=\"plotly\", include_plotlyjs=\"cdn\")\n", + "for name in (\"figure_bundled.html\", \"figure_cdn.html\"):\n", + " print(f\"{name}: {os.path.getsize(name) / 1024:.0f} kB\")" + ] + }, + { + "cell_type": "markdown", + "id": "22", + "metadata": {}, + "source": [ + "`canvas.to_html()` returns the HTML as a string instead, with plotly.js from the CDN\n", + "by default. `full_html=False` gives just the `
` and `