diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2792bebb..52a7dbf0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -109,32 +109,6 @@ jobs: meta.setdefault("language_info", {}) meta["language_info"]["name"] = "python" - for cell in nb.get("cells", []): - if cell.get("cell_type") != "code": - continue - source = cell.get("source", []) - if isinstance(source, str): - lines = source.splitlines(keepends=True) - else: - lines = source - - new_lines = [] - changed = False - for line in lines: - if line.strip() in ("%matplotlib ipympl", "%matplotlib widget"): - newline = "\n" if line.endswith("\n") else "" - new_lines.append(f"%matplotlib inline{newline}") - changed = True - else: - new_lines.append(line) - - if changed: - cell["source"] = ( - new_lines - if not isinstance(source, str) - else "".join(new_lines) - ) - with nb_path.open("w", encoding="utf-8") as f: json.dump(nb, f, indent=1) f.write("\n") @@ -147,11 +121,13 @@ jobs: # ships JSPI, and the old Pyodide then misbehaved there (the kernel never # finished starting). A browser with no JSPI (Safari before 27; Firefox # before 153) is now told so by a banner, added below, not supported by a pin. + # ipympl is installed here so that the site carries the jupyter-matplotlib + # extension, which the notebooks' %matplotlib ipympl needs in the browser. # Installing jupyterlite-core directly rather than the jupyterlite metapackage. # Keep docs/lite/wasm_check/package.json's pyodide in step with the Pyodide # that the kernel bundles (0.8.7 bundles 314.0.6). run: | - pip install jupyterlite-core "jupyterlite-pyodide-kernel>=0.8.7" jupyter-server + pip install jupyterlite-core "jupyterlite-pyodide-kernel>=0.8.7" jupyter-server ipympl cd docs/lite && jupyter lite build --output-dir ../build/html/lite - name: Add the browser capability check to JupyterLite diff --git a/docs/notebooks/IBVS.ipynb b/docs/notebooks/IBVS.ipynb index 009825dc..64fe26b1 100644 --- a/docs/notebooks/IBVS.ipynb +++ b/docs/notebooks/IBVS.ipynb @@ -28,7 +28,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -50,7 +50,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -148,7 +148,7 @@ "import numpy as np\n", "import math\n", "\n", - "%matplotlib inline\n", + "%matplotlib ipympl\n", "\n", "np.set_printoptions(linewidth=120, formatter={'float': lambda x: f\"{x:8.4g}\" if abs(x) > 1e-10 else f\"{0:8.4g}\"})\n", "from machinevisiontoolbox import Image, CentralCamera\n", @@ -252,8 +252,7 @@ "outputs": [], "source": [ "# setup the plot\n", - "plt.figure()\n", - "ax = plt.gca()\n", + "fig, ax = plt.subplots()\n", "plt.grid(True)\n", "ax.set_aspect('equal')\n", "ax.set_facecolor('yellow')\n", @@ -290,8 +289,7 @@ " [900, 180],\n", " [500, 870] ]).T\n", "\n", - "plt.figure()\n", - "ax = plt.gca()\n", + "fig, ax = plt.subplots()\n", "plt.grid(True)\n", "ax.set_aspect('equal')\n", "ax.set_facecolor('yellow')\n", @@ -302,8 +300,7 @@ "ax.set_ylim(1000, 0) # inverted y-axis\n", "\n", "plt.plot(p[0,:], p[1,:], 'o');\n", - "plt.plot(pstar[0,:], pstar[1,:], 'r*', markersize=16);\n", - "plt.show()" + "plt.plot(pstar[0,:], pstar[1,:], 'r*', markersize=16);" ] }, { @@ -348,9 +345,7 @@ }, "outputs": [], "source": [ - "plt.clf()\n", - "plt.figure()\n", - "ax = plt.gca()\n", + "fig, ax = plt.subplots()\n", "plt.grid(True)\n", "ax.set_aspect('equal')\n", "ax.set_facecolor('yellow')\n", @@ -550,7 +545,7 @@ }, "outputs": [], "source": [ - "plt.figure()\n", + "fig, ax = plt.subplots()\n", "plt.plot(pstar[0,:], pstar[1,:], 'r*', markersize=16);\n", "plt.xlabel('X')\n", "plt.ylabel('Y')\n", @@ -605,6 +600,7 @@ }, "outputs": [], "source": [ + "fig, ax = plt.subplots()\n", "plt.plot(pose_history.t)\n", "plt.legend(list(\"XYZ\"))\n", "plt.xlabel('time step')\n", @@ -630,6 +626,7 @@ }, "outputs": [], "source": [ + "fig, ax = plt.subplots()\n", "plt.plot(enorm_history)\n", "plt.xlabel('time step')\n", "plt.ylabel('$\\|e\\|$')\n", diff --git a/docs/notebooks/_mvtb_nb_bootstrap.py b/docs/notebooks/_mvtb_nb_bootstrap.py index ddb61ebc..2615b392 100644 --- a/docs/notebooks/_mvtb_nb_bootstrap.py +++ b/docs/notebooks/_mvtb_nb_bootstrap.py @@ -34,6 +34,7 @@ "numpy", "scipy", "matplotlib", + "ipympl", "pillow", "typing_extensions", "opencv-python", diff --git a/docs/notebooks/calibration.ipynb b/docs/notebooks/calibration.ipynb index 52e8b654..2b0411be 100644 --- a/docs/notebooks/calibration.ipynb +++ b/docs/notebooks/calibration.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -141,6 +141,9 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib ipympl\n", + "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "from machinevisiontoolbox import *\n", "import numpy as np\n", "np.set_printoptions(linewidth=120, formatter={'float': lambda x: f\"{x:8.4g}\" if abs(x) > 1e-10 else f\"{0:8.4g}\"})" @@ -499,7 +502,7 @@ "metadata": {}, "outputs": [], "source": [ - "plt.clf() # clear 3D plot\n", + "fig, ax = plt.subplots()\n", "plt.quiver(Ud[::50, ::50], Vd[::50, ::50], -delta_u[::50, ::50], -delta_v[::50, ::50]);" ] }, diff --git a/docs/notebooks/camera.ipynb b/docs/notebooks/camera.ipynb index 2d6b5ef4..cdc97b15 100644 --- a/docs/notebooks/camera.ipynb +++ b/docs/notebooks/camera.ipynb @@ -30,7 +30,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -52,7 +52,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -147,7 +147,9 @@ }, "outputs": [], "source": [ - "%matplotlib inline\n", + "%matplotlib ipympl\n", + "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "import numpy as np\n", "import math\n", diff --git a/docs/notebooks/camera_animation.ipynb b/docs/notebooks/camera_animation.ipynb index c0088e75..4aa1f225 100644 --- a/docs/notebooks/camera_animation.ipynb +++ b/docs/notebooks/camera_animation.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -141,12 +141,13 @@ "metadata": {}, "outputs": [], "source": [ + "%matplotlib ipympl\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "from mpl_toolkits.mplot3d import Axes3D\n", "import mpl_toolkits.mplot3d.art3d as art3d\n", - "import ipywidgets as widgets\n", - "%matplotlib inline" + "import ipywidgets as widgets\n" ] }, { @@ -188,13 +189,16 @@ " [ 5, 5],\n", " [ 5, -5] ])\n", "\n", + "# create the figure once, the slider callback redraws it\n", + "fig = plt.figure(figsize=(10, 10))\n", + "ax = fig.add_subplot(projection='3d')\n", + "\n", "@widgets.interact\n", "def animate( X = widgets.FloatSlider(value=1, description='X:', min=-4, max=4),\n", " Y = widgets.FloatSlider(value=1, description='Y:', min=-4, max=4),\n", " Z = widgets.FloatSlider(value=2, description='Z:', min=1, max=5),\n", " f = widgets.FloatSlider(value=1, description='f', min=0.1, max=1.5)):\n", - " fig = plt.figure(figsize=(10, 10))\n", - " ax = plt.axes(projection='3d')\n", + " ax.clear()\n", " p = plt.Polygon(verts, alpha=0.7, color=\"lightyellow\")\n", "\n", " ax.add_patch(p)\n", @@ -216,7 +220,7 @@ "\n", " ax.text(X, Y, Z, \" P\")\n", " ax.text(x, y, f, \" p = (%.3f, %.3f)\" % (x, y))\n", - " plt.show()\n", + " fig.canvas.draw_idle()\n", " \n", " # uv_coords.value = \"Image-plane coordinate: (%.3f, %.3f)\" % (x, y)\n" ] diff --git a/docs/notebooks/color-images.ipynb b/docs/notebooks/color-images.ipynb index d61ba320..ee66904d 100644 --- a/docs/notebooks/color-images.ipynb +++ b/docs/notebooks/color-images.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -141,8 +141,9 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib widget\n", + "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "import numpy as np\n", "from machinevisiontoolbox import *\n", @@ -520,7 +521,6 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure()\n", "hist.plot(type=\"frequency\", style=\"stack\")" ] }, diff --git a/docs/notebooks/exploring-images.ipynb b/docs/notebooks/exploring-images.ipynb index 0d078276..d7d4d999 100644 --- a/docs/notebooks/exploring-images.ipynb +++ b/docs/notebooks/exploring-images.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -56,7 +56,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -150,6 +150,8 @@ "outputs": [], "source": [ "%matplotlib ipympl\n", + "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "from machinevisiontoolbox import Image" ] }, diff --git a/docs/notebooks/fiducials.ipynb b/docs/notebooks/fiducials.ipynb index e9cf77d6..6ab6bda0 100644 --- a/docs/notebooks/fiducials.ipynb +++ b/docs/notebooks/fiducials.ipynb @@ -30,7 +30,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -52,7 +52,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -155,7 +155,8 @@ "from spatialmath.base import e2h, h2e\n", "from machinevisiontoolbox import Image, CentralCamera\n", "from spatialmath.base import plot_point\n", - "import matplotlib.pyplot as plt\n" + "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n" ] }, { @@ -307,7 +308,7 @@ }, "outputs": [], "source": [ - "scene.disp(block=None)\n", + "scene.disp()\n", "plot_point(marker.corners, 'bx')\n", "plt.xlim(800, 1200)\n", "plt.ylim(1200, 800)" diff --git a/docs/notebooks/finding-blobs.ipynb b/docs/notebooks/finding-blobs.ipynb index b6bdb029..2be95dd7 100644 --- a/docs/notebooks/finding-blobs.ipynb +++ b/docs/notebooks/finding-blobs.ipynb @@ -30,7 +30,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -52,7 +52,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -149,6 +149,7 @@ "source": [ "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "import matplotlib\n", "matplotlib.rcParams[\"figure.figsize\"] = [8, 8]\n", "\n", @@ -255,7 +256,7 @@ "metadata": {}, "outputs": [], "source": [ - "sharks.disp(block=None)\n", + "sharks.disp()\n", "blobs.plot_labelbox(color=\"yellow\", linewidth=2)" ] }, @@ -447,7 +448,7 @@ }, "outputs": [], "source": [ - "sharks.disp(block=None)\n", + "sharks.disp()\n", "blobs.plot_box(color=\"yellow\", linewidth=2)\n", "blobs.plot_centroid()" ] @@ -602,7 +603,6 @@ " colormap=\"viridis\",\n", " ncolors=10,\n", " colorbar=dict(shrink=0.8, aspect=20 * 0.8),\n", - " block=True,\n", ")" ] }, diff --git a/docs/notebooks/gamma.ipynb b/docs/notebooks/gamma.ipynb index 534f27e3..b528644c 100644 --- a/docs/notebooks/gamma.ipynb +++ b/docs/notebooks/gamma.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -141,8 +141,9 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib widget\n", + "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "import numpy as np\n", "from machinevisiontoolbox import *\n", diff --git a/docs/notebooks/greyscale-images.ipynb b/docs/notebooks/greyscale-images.ipynb index 14811354..78612aaf 100644 --- a/docs/notebooks/greyscale-images.ipynb +++ b/docs/notebooks/greyscale-images.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -141,8 +141,9 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib widget\n", + "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "import numpy as np\n", "from machinevisiontoolbox import *\n", @@ -194,6 +195,7 @@ "metadata": {}, "outputs": [], "source": [ + "fig, ax = plt.subplots()\n", "plt.imshow(a) # display the array using Matplotlib\n", "plt.draw()" ] @@ -481,7 +483,6 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure()\n", "hist.plot()" ] }, @@ -502,7 +503,6 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure()\n", "hist.plot('ncdf')\n" ] }, @@ -673,7 +673,6 @@ "outputs": [], "source": [ "hist = castle.hist()\n", - "plt.figure()\n", "hist.plot()" ] }, diff --git a/docs/notebooks/homogeneous-coords.ipynb b/docs/notebooks/homogeneous-coords.ipynb index ed6aa02e..1c14ded5 100644 --- a/docs/notebooks/homogeneous-coords.ipynb +++ b/docs/notebooks/homogeneous-coords.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -146,6 +146,7 @@ "\n", "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "from spatialmath.base import colvec, e2h, h2e\n", "# from IPython.core.display import HTML\n", "# HTML(open(\"extra.css\", \"r\").read())" @@ -346,7 +347,7 @@ "\n", "# Create the figure and axis once\n", "fig = plt.figure()\n", - "ax = plt.axes(projection='3d')\n", + "ax = fig.add_subplot(projection='3d')\n", "p = plt.Polygon(verts, alpha=0.7, color=\"r\")\n", "\n", "ax.add_patch(p)\n", @@ -497,7 +498,7 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure()\n", + "fig, ax = plt.subplots()\n", "plt.plot(p1[0], p1[1], 'ro')\n", "plt.plot(p2[0], p2[1], 'bo')\n", "x = np.linspace(0, 4, 100) # x span for the line segment\n", @@ -559,7 +560,7 @@ "source": [ "# plot the lines for x=[0,4]\n", "x = np.linspace(0, 4, 100)\n", - "plt.figure()\n", + "fig, ax = plt.subplots()\n", "plt.plot(x, x-2, 'r')\n", "plt.plot(x, -2*x+6, 'b')\n", "\n", diff --git a/docs/notebooks/homography.ipynb b/docs/notebooks/homography.ipynb index 3d93e0ad..2d30f237 100644 --- a/docs/notebooks/homography.ipynb +++ b/docs/notebooks/homography.ipynb @@ -30,7 +30,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -52,7 +52,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -148,6 +148,8 @@ "outputs": [], "source": [ "%matplotlib ipympl\n", + "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "import numpy as np\n", "np.set_printoptions(linewidth=120, formatter={'float': lambda x: f\"{x:8.4g}\" if abs(x) > 1e-10 else f\"{0:8.4g}\"})\n", diff --git a/docs/notebooks/image-convolution.ipynb b/docs/notebooks/image-convolution.ipynb index 39aba54b..c4a1a1a7 100644 --- a/docs/notebooks/image-convolution.ipynb +++ b/docs/notebooks/image-convolution.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -141,8 +141,9 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib widget\n", + "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "import numpy as np\n", "from machinevisiontoolbox import *\n", diff --git a/docs/notebooks/image-features.ipynb b/docs/notebooks/image-features.ipynb index 9c35ed1a..7a8513dd 100644 --- a/docs/notebooks/image-features.ipynb +++ b/docs/notebooks/image-features.ipynb @@ -30,7 +30,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -52,7 +52,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -149,6 +149,7 @@ "source": [ "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "import matplotlib\n", "matplotlib.rcParams['figure.figsize'] = [8, 8]\n", "\n", @@ -343,7 +344,7 @@ "v = np.array([uv[1][i] for i in k])\n", "\n", "# display the image, and overlay with markers for each detected corner feature\n", - "castle.disp(darken=True, block=None);\n", + "castle.disp(darken=True);\n", "plot_point((u, v), 'y+');" ] }, @@ -629,7 +630,7 @@ }, "outputs": [], "source": [ - "butterfly.disp(block=None)\n", + "butterfly.disp()\n", "features.sort(by='scale')[:50].plot(filled=True, alpha=0.5)" ] }, @@ -680,7 +681,7 @@ }, "outputs": [], "source": [ - "butterfly.disp(block=None)\n", + "butterfly.disp()\n", "features.sort(by='scale')[:50].plot(filled=True, alpha=0.5, hand=True)" ] }, @@ -795,7 +796,7 @@ }, "outputs": [], "source": [ - "matches[:100].plot('y', alpha=0.6, block=None)" + "matches[:100].plot('y', alpha=0.6)" ] }, { diff --git a/docs/notebooks/image-motion.ipynb b/docs/notebooks/image-motion.ipynb index 6d50eeb7..568176d7 100644 --- a/docs/notebooks/image-motion.ipynb +++ b/docs/notebooks/image-motion.ipynb @@ -28,7 +28,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -50,7 +50,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -150,8 +150,9 @@ "from spatialmath import SE3\n", "import scipy.linalg as lin\n", "\n", - "%matplotlib inline\n", + "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "np.set_printoptions(linewidth=120, formatter={'float': lambda x: f\"{x:8.4g}\" if abs(x) > 1e-10 else f\"{0:8.4g}\"})\n" ] }, @@ -460,6 +461,8 @@ "\n", "camera = CentralCamera.Default() # create camera object\n", "\n", + "# create the figure once, the slider callback redraws it\n", + "fig, ax = plt.subplots(figsize=(8, 8))\n", "\n", "@widgets.interact\n", "def animate( x = widgets.FloatSlider(value=0, description='X:', min=-1, max=1),\n", @@ -473,8 +476,7 @@ " vel = [x, y, z, rx, ry, rz] # camera velocity from sliders, as a column vector\n", " \n", " # setup the plot window, fixed scale, unity aspect ratio, grid lines on\n", - " plt.figure(figsize=(8,8))\n", - " ax = plt.gca()\n", + " ax.clear()\n", " plt.grid(True)\n", " ax.set_aspect('equal')\n", " ax.set_facecolor('yellow')\n", @@ -502,7 +504,8 @@ " # -dv is to overcome a bug with quiver and flipped vertical axis\n", " plt.quiver(U, V, du, -dv, scale=8000)\n", " \n", - " " + " \n", + " fig.canvas.draw_idle()\n" ] }, { diff --git a/docs/notebooks/image-processing.ipynb b/docs/notebooks/image-processing.ipynb index c563578f..69bd740b 100644 --- a/docs/notebooks/image-processing.ipynb +++ b/docs/notebooks/image-processing.ipynb @@ -26,7 +26,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -48,7 +48,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -141,8 +141,9 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib widget\n", + "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "import numpy as np\n", "from machinevisiontoolbox import *\n", @@ -229,7 +230,6 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure()\n", "histo.plot()" ] }, @@ -349,7 +349,6 @@ "outputs": [], "source": [ "h = cc.plane('g').hist()\n", - "plt.figure()\n", "h.plot()\n", "plt.xlabel('Chromaticity (g)');\n", "plt.grid(True)\n", diff --git a/docs/notebooks/intro.ipynb b/docs/notebooks/intro.ipynb index 93b93a9b..dc0b12b1 100644 --- a/docs/notebooks/intro.ipynb +++ b/docs/notebooks/intro.ipynb @@ -15,7 +15,7 @@ "We need to import some packages to help us with linear algebra (`numpy`), graphics (`matplotlib`), and machine vision (`machinevisiontoolbox`). If you're running locally you need to have these packages installed.\n", "\n", "
\n", - "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow. In the browser environment it is not possible to examine pixel values by hovering the mouse cursor over an image (this is a limitation of Matplotlib in a Pyodide Web Worker).\n", + "If you're running on CoLab or in the browser we have to first install machinevisiontoolbox, which is not preinstalled, so the next cell will be slow.\n", "
" ] }, @@ -37,7 +37,7 @@ "PACKAGE = 'machinevision-toolbox-python'\n", "IMPORT_NAME = 'machinevisiontoolbox'\n", "GIT_URL: str | None = 'https://github.com/petercorke/machinevision-toolbox-python'\n", - "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", + "JL_PACKAGES = ['numpy', 'scipy', 'matplotlib', 'ipympl', 'pillow', 'typing_extensions', 'opencv-python', 'ansitable', 'mvtb-data', 'tqdm', 'requests', 'ipywidgets', 'spatialmath-python', 'pgraph-python']\n", "JL_NO_DEPS: list[str] = []\n", "JL_PACKAGE_NO_DEPS = True\n", "JL_EXTRAS: dict[str, list[str]] = {}\n", @@ -140,8 +140,9 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib inline\n", + "%matplotlib ipympl\n", "import matplotlib.pyplot as plt\n", + "plt.close(\"all\") # re-running the notebook from the top starts with no figures\n", "\n", "from machinevisiontoolbox import Image\n", "\n", @@ -210,9 +211,9 @@ "grey = mona.mono()\n", "print(f\"grey: {grey.width} x {grey.height}, planes: {grey.nplanes}\")\n", "\n", - "hist, x = grey.hist()\n", - "plt.figure()\n", - "plt.bar(x, hist, width=1, color=\"steelblue\")\n", + "hist = grey.hist()\n", + "fig, ax = plt.subplots()\n", + "plt.bar(hist.x, hist.h, width=1, color=\"steelblue\")\n", "plt.xlabel(\"Pixel value\")\n", "plt.ylabel(\"Count\")\n", "plt.title(\"Greyscale histogram\")\n", @@ -269,8 +270,8 @@ "\n", "fig, ax = plt.subplots()\n", "sharks.disp(ax=ax)\n", - "blobs.plot_box(ax, color=\"g\")\n", - "blobs.plot_centroid(ax, \"o\", color=\"y\")\n", + "blobs.plot_box(color=\"g\")\n", + "blobs.plot_centroid(\"o\", color=\"y\")\n", "plt.tight_layout()" ] },