diff --git a/docs/source/conf.py b/docs/source/conf.py index 38133c901..4d94ec7e7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -2,7 +2,24 @@ # # For the full list of built-in configuration values, see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html + +import os + +# need to force offscreen rendering before importing fpl +# otherwise fpl tries to select glfw canvas +os.environ["WGPU_FORCE_OFFSCREEN"] = "1" + import fastplotlib +from pygfx.utils.gallery_scraper import find_examples_for_gallery +from pathlib import Path +import sys +from sphinx_gallery.sorting import ExplicitOrder +import imageio.v3 as iio + +ROOT_DIR = Path(__file__).parents[1].parents[0] # repo root +EXAMPLES_DIR = Path.joinpath(ROOT_DIR, "examples", "desktop") + +sys.path.insert(0, str(ROOT_DIR)) # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information @@ -23,8 +40,40 @@ "sphinx.ext.viewcode", "sphinx_copybutton", "sphinx_design", + "sphinx_gallery.gen_gallery" ] +sphinx_gallery_conf = { + "gallery_dirs": "_gallery", + "backreferences_dir": "_gallery/backreferences", + "doc_module": ("fastplotlib",), + "image_scrapers": ("pygfx",), + "remove_config_comments": True, + "subsection_order": ExplicitOrder( + [ + "../../examples/desktop/image", + "../../examples/desktop/gridplot", + "../../examples/desktop/line", + "../../examples/desktop/line_collection", + "../../examples/desktop/scatter", + "../../examples/desktop/heatmap", + "../../examples/desktop/misc" + ] + ), + "ignore_pattern": r'__init__\.py', + "nested_sections": False, + "thumbnail_size": (250, 250) +} + +extra_conf = find_examples_for_gallery(EXAMPLES_DIR) +sphinx_gallery_conf.update(extra_conf) + +# download imageio examples for the gallery +iio.imread("imageio:clock.png") +iio.imread("imageio:astronaut.png") +iio.imread("imageio:coffee.png") +iio.imread("imageio:hubble_deep_field.png") + autosummary_generate = True templates_path = ["_templates"] @@ -56,7 +105,7 @@ } html_theme_options = { - "source_repository": "https://github.com/kushalkolar/fastplotlib", + "source_repository": "https://github.com/fastplotlib/fastplotlib", "source_branch": "main", "source_directory": "docs/", } diff --git a/docs/source/index.rst b/docs/source/index.rst index e99e38c52..6385c2aee 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -20,6 +20,12 @@ Welcome to fastplotlib's documentation! Utils GPU +.. toctree:: + :caption: Gallery + :maxdepth: 1 + + Gallery <_gallery/index> + Summary ======= diff --git a/examples/README.rst b/examples/README.rst new file mode 100644 index 000000000..138ec748b --- /dev/null +++ b/examples/README.rst @@ -0,0 +1,2 @@ +Examples that use fastplotlib +============================= diff --git a/examples/desktop/gridplot/__init__.py b/examples/desktop/README.rst similarity index 100% rename from examples/desktop/gridplot/__init__.py rename to examples/desktop/README.rst diff --git a/examples/desktop/gridplot/README.rst b/examples/desktop/gridplot/README.rst new file mode 100644 index 000000000..486e708e7 --- /dev/null +++ b/examples/desktop/gridplot/README.rst @@ -0,0 +1,2 @@ +GridPlot Examples +================= diff --git a/examples/desktop/gridplot/gridplot.py b/examples/desktop/gridplot/gridplot.py index 2669dd49b..044adae80 100644 --- a/examples/desktop/gridplot/gridplot.py +++ b/examples/desktop/gridplot/gridplot.py @@ -1,34 +1,37 @@ """ GridPlot Simple -============ +=============== + Example showing simple 2x2 GridPlot with Standard images from imageio. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import imageio.v3 as iio - -fig = fpl.Figure(shape=(2, 2)) +figure = fpl.Figure(shape=(2, 2)) im = iio.imread("imageio:clock.png") im2 = iio.imread("imageio:astronaut.png") im3 = iio.imread("imageio:coffee.png") im4 = iio.imread("imageio:hubble_deep_field.png") -fig[0, 0].add_image(data=im) -fig[0, 1].add_image(data=im2) -fig[1, 0].add_image(data=im3) -fig[1, 1].add_image(data=im4) +figure[0, 0].add_image(data=im) +figure[0, 1].add_image(data=im2) +figure[1, 0].add_image(data=im3) +figure[1, 1].add_image(data=im4) -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) -for subplot in fig: +for subplot in figure: subplot.auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/gridplot/gridplot_non_square.py b/examples/desktop/gridplot/gridplot_non_square.py index ea93096dc..c8a68cc85 100644 --- a/examples/desktop/gridplot/gridplot_non_square.py +++ b/examples/desktop/gridplot/gridplot_non_square.py @@ -1,32 +1,35 @@ """ -GridPlot Simple -============ +GridPlot Non-Square Example +=========================== + Example showing simple 2x2 GridPlot with Standard images from imageio. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import imageio.v3 as iio - -fig = fpl.Figure(shape=(2, 2), controller_ids="sync") +figure = fpl.Figure(shape=(2, 2), controller_ids="sync") im = iio.imread("imageio:clock.png") im2 = iio.imread("imageio:astronaut.png") im3 = iio.imread("imageio:coffee.png") -fig[0, 0].add_image(data=im) -fig[0, 1].add_image(data=im2) -fig[1, 0].add_image(data=im3) +figure[0, 0].add_image(data=im) +figure[0, 1].add_image(data=im2) +figure[1, 0].add_image(data=im3) -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) -for subplot in fig: +for subplot in figure: subplot.auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/gridplot/multigraphic_gridplot.py b/examples/desktop/gridplot/multigraphic_gridplot.py new file mode 100644 index 000000000..3d8dbe4a8 --- /dev/null +++ b/examples/desktop/gridplot/multigraphic_gridplot.py @@ -0,0 +1,116 @@ +""" +Multi-Graphic GridPlot +====================== + +Example showing a Figure with multiple subplots and multiple graphic types. +""" + +# test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' + +import fastplotlib as fpl +import numpy as np +import imageio.v3 as iio +from itertools import product + +# define figure +figure = fpl.Figure(shape=(2, 2), names=[["image-overlay", "circles"], ["line-stack", "scatter"]]) + +img = iio.imread("imageio:coffee.png") + +# add image to subplot +figure["image-overlay"].add_image(data=img) + +# generate overlay + +# empty array for overlay, shape is [nrows, ncols, RGBA] +overlay = np.zeros(shape=(*img.shape[:2], 4), dtype=np.float32) + +# set the blue values of some pixels with an alpha > 1 +overlay[img[:, :, -1] > 200] = np.array([0.0, 0.0, 1.0, 0.6]).astype(np.float32) + +# add overlay to image +figure["image-overlay"].add_image(data=overlay) + +# generate some circles +def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray: + theta = np.linspace(0, 2 * np.pi, n_points) + xs = radius * np.sin(theta) + ys = radius * np.cos(theta) + + return np.column_stack([xs, ys]) + center + + +spatial_dims = (50, 50) + +# this makes 16 circles, so we can create 16 cmap values, so it will use these values to set the +# color of the line based by using the cmap as a LUT with the corresponding cmap_transform +circles = list() +for center in product(range(0, spatial_dims[0], 15), range(0, spatial_dims[1], 15)): + circles.append(make_circle(center, 5, n_points=75)) + +# things like class labels, cluster labels, etc. +cmap_transform = [ + 0, 1, 1, 2, + 0, 0, 1, 1, + 2, 2, 8, 3, + 1, 9, 1, 5 +] + +# add an image to overlay the circles on +img2 = np.ones((60, 60)) + +figure["circles"].add_image(data=img2) + +# add the circles to the figure +figure["circles"].add_line_collection( + circles, + cmap="tab10", + cmap_transform=cmap_transform, + thickness=3, + alpha=0.5, + name="circles-graphic" +) + +# move the circles graphic so that it is centered over the image +figure["circles"]["circles-graphic"].offset = np.array([7, 7, 2]) + +# generate some sine data +# linspace, create 100 evenly spaced x values from -10 to 10 +xs = np.linspace(-10, 10, 100) +# sine wave +ys = np.sin(xs) +sine = np.dstack([xs, ys])[0] + +# make 10 identical waves +sine_waves = 10 * [sine] + +# add the line stack to the figure +figure["line-stack"].add_line_stack(data=sine_waves, cmap="Wistia", separation=1) + +figure["line-stack"].auto_scale(maintain_aspect=True) + +# generate some scatter data +# create a gaussian cloud of 500 points +n_points = 500 + +mean = [0, 0] # mean of the Gaussian distribution +covariance = [[1, 0], [0, 1]] # covariance matrix + +gaussian_cloud = np.random.multivariate_normal(mean, covariance, n_points) +gaussian_cloud2 = np.random.multivariate_normal(mean, covariance, n_points) + +# add the scatter graphics to the figure +figure["scatter"].add_scatter(data=gaussian_cloud, sizes=1, cmap="jet") +figure["scatter"].add_scatter(data=gaussian_cloud2, colors="r", sizes=1) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() + diff --git a/examples/desktop/heatmap/README.rst b/examples/desktop/heatmap/README.rst new file mode 100644 index 000000000..64294f46f --- /dev/null +++ b/examples/desktop/heatmap/README.rst @@ -0,0 +1,2 @@ +Heatmap Examples +================ diff --git a/examples/desktop/heatmap/__init__.py b/examples/desktop/heatmap/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/desktop/heatmap/heatmap.py b/examples/desktop/heatmap/heatmap.py index f3a1bf460..08b284749 100644 --- a/examples/desktop/heatmap/heatmap.py +++ b/examples/desktop/heatmap/heatmap.py @@ -5,12 +5,12 @@ """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(0, 1_000, 10_000, dtype=np.float32) @@ -19,14 +19,16 @@ data = np.vstack([sine * i for i in range(20_000)]) # plot the image data -img = fig[0, 0].add_image(data=data, name="heatmap") +img = figure[0, 0].add_image(data=data, name="heatmap") -fig.show() +figure.show() -fig.canvas.set_logical_size(1500, 1500) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/heatmap/heatmap_cmap.py b/examples/desktop/heatmap/heatmap_cmap.py index 39e697c93..f51981bed 100644 --- a/examples/desktop/heatmap/heatmap_cmap.py +++ b/examples/desktop/heatmap/heatmap_cmap.py @@ -4,13 +4,14 @@ Change the cmap of a heatmap """ + # test_example = false +# sphinx_gallery_pygfx_docs = 'hidden' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(0, 1_000, 10_000, dtype=np.float32) @@ -19,16 +20,18 @@ data = np.vstack([sine * i for i in range(20_000)]) # plot the image data -img = fig[0, 0].add_image(data=data, name="heatmap") +img = figure[0, 0].add_image(data=data, name="heatmap") -fig.show() +figure.show() -fig.canvas.set_logical_size(1500, 1500) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() img.cmap = "viridis" +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/heatmap/heatmap_data.py b/examples/desktop/heatmap/heatmap_data.py index 75ef3ce41..9334ea4d7 100644 --- a/examples/desktop/heatmap/heatmap_data.py +++ b/examples/desktop/heatmap/heatmap_data.py @@ -5,12 +5,12 @@ """ # test_example = false +# sphinx_gallery_pygfx_docs = 'hidden' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(0, 1_000, 9_000, dtype=np.float32) @@ -19,18 +19,20 @@ data = np.vstack([sine * i for i in range(9_000)]) # plot the image data -img = fig[0, 0].add_image(data=data, name="heatmap") +img = figure[0, 0].add_image(data=data, name="heatmap") -fig.show() +figure.show() -fig.canvas.set_logical_size(1500, 1500) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() cosine = np.cos(np.sqrt(xs)[:3000]) # change first 2,000 rows and 3,000 columns img.data[:2_000, :3_000] = np.vstack([cosine * i * 4 for i in range(2_000)]) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/heatmap/heatmap_square.py b/examples/desktop/heatmap/heatmap_square.py index f776b74e1..51e71695a 100644 --- a/examples/desktop/heatmap/heatmap_square.py +++ b/examples/desktop/heatmap/heatmap_square.py @@ -5,12 +5,13 @@ """ # test_example = false +# sphinx_gallery_pygfx_docs = 'hidden' import fastplotlib as fpl import numpy as np -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(0, 1_000, 20_000, dtype=np.float32) @@ -19,14 +20,14 @@ data = np.vstack([sine * i for i in range(20_000)]) # plot the image data -img = fig[0, 0].add_image(data=data, name="heatmap") +img = figure[0, 0].add_image(data=data, name="heatmap") del data # data no longer needed after given to graphic -fig.show() +figure.show() -fig.canvas.set_logical_size(1500, 1500) +figure.canvas.set_logical_size(1500, 1500) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() if __name__ == "__main__": print(__doc__) diff --git a/examples/desktop/heatmap/heatmap_vmin_vmax.py b/examples/desktop/heatmap/heatmap_vmin_vmax.py index 75b6b7b68..45c960fd8 100644 --- a/examples/desktop/heatmap/heatmap_vmin_vmax.py +++ b/examples/desktop/heatmap/heatmap_vmin_vmax.py @@ -5,12 +5,12 @@ """ # test_example = false +# sphinx_gallery_pygfx_docs = 'hidden' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(0, 1_000, 10_000, dtype=np.float32) @@ -19,17 +19,19 @@ data = np.vstack([sine * i for i in range(20_000)]) # plot the image data -img = fig[0, 0].add_image(data=data, name="heatmap") +img = figure[0, 0].add_image(data=data, name="heatmap") -fig.show() +figure.show() -fig.canvas.set_logical_size(1500, 1500) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() img.vmin = -5_000 img.vmax = 10_000 +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/heatmap/heatmap_wide.py b/examples/desktop/heatmap/heatmap_wide.py index 251c25fa4..dccf531e2 100644 --- a/examples/desktop/heatmap/heatmap_wide.py +++ b/examples/desktop/heatmap/heatmap_wide.py @@ -5,12 +5,13 @@ """ # test_example = false +# sphinx_gallery_pygfx_docs = 'hidden' import fastplotlib as fpl import numpy as np -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(0, 1_000, 20_000, dtype=np.float32) @@ -19,13 +20,13 @@ data = np.vstack([sine * i for i in range(10_000)]) # plot the image data -img = fig[0, 0].add_image(data=data, name="heatmap") +img = figure[0, 0].add_image(data=data, name="heatmap") -fig.show() +figure.show() -fig.canvas.set_logical_size(1500, 1500) +figure.canvas.set_logical_size(1500, 1500) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() if __name__ == "__main__": print(__doc__) diff --git a/examples/desktop/image/README.rst b/examples/desktop/image/README.rst new file mode 100644 index 000000000..028e85ec5 --- /dev/null +++ b/examples/desktop/image/README.rst @@ -0,0 +1,2 @@ +Image Examples +============== diff --git a/examples/desktop/image/__init__.py b/examples/desktop/image/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/desktop/image/image_cmap.py b/examples/desktop/image/image_cmap.py index bb8e9f9d8..c70af7346 100644 --- a/examples/desktop/image/image_cmap.py +++ b/examples/desktop/image/image_cmap.py @@ -1,29 +1,33 @@ """ -Simple Plot -============ +Image Colormap +============== + Example showing simple plot creation and subsequent cmap change with Standard image from imageio. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import imageio.v3 as iio im = iio.imread("imageio:camera.png") -fig = fpl.Figure() +figure = fpl.Figure() # plot the image data -image_graphic = fig[0, 0].add_image(data=im, name="random-image") +image_graphic = figure[0, 0].add_image(data=im, name="random-image") -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() image_graphic.cmap = "viridis" +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/image/image_rgb.py b/examples/desktop/image/image_rgb.py index ce7e151d0..951142fd7 100644 --- a/examples/desktop/image/image_rgb.py +++ b/examples/desktop/image/image_rgb.py @@ -1,29 +1,31 @@ """ -Simple Plot -============ +RGB Image +========= + Example showing the simple plot creation with 512 x 512 2D RGB image. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import imageio.v3 as iio - im = iio.imread("imageio:astronaut.png") -fig = fpl.Figure() +figure = fpl.Figure() # plot the image data -image_graphic = fig[0, 0].add_image(data=im, name="iio astronaut") - -fig.show() +image_graphic = figure[0, 0].add_image(data=im, name="iio astronaut") -fig.canvas.set_logical_size(800, 800) +figure.show() -fig[0, 0].auto_scale() +figure.canvas.set_logical_size(700, 560) +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/image/image_rgbvminvmax.py b/examples/desktop/image/image_rgbvminvmax.py index 56114e1e3..25d3904e8 100644 --- a/examples/desktop/image/image_rgbvminvmax.py +++ b/examples/desktop/image/image_rgbvminvmax.py @@ -1,32 +1,34 @@ """ -Simple Plot -============ +RGB Image Vmin/Vmax +=================== + Example showing the simple plot followed by changing the vmin/vmax with 512 x 512 2D RGB image. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import imageio.v3 as iio - im = iio.imread("imageio:astronaut.png") -fig = fpl.Figure() +figure = fpl.Figure() # plot the image data -image_graphic = fig[0, 0].add_image(data=im, name="iio astronaut") +image_graphic = figure[0, 0].add_image(data=im, name="iio astronaut") -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() image_graphic.vmin = 0.5 image_graphic.vmax = 0.75 - +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/image/image_simple.py b/examples/desktop/image/image_simple.py index a640974ed..dab5188a1 100644 --- a/examples/desktop/image/image_simple.py +++ b/examples/desktop/image/image_simple.py @@ -1,28 +1,31 @@ """ -Simple Plot +Simple Image ============ + Example showing the simple plot creation with Standard imageio image. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import imageio.v3 as iio - -fig = fpl.Figure() +figure = fpl.Figure() data = iio.imread("imageio:camera.png") # plot the image data -image_graphic = fig[0, 0].add_image(data=data, name="iio camera") +image_graphic = figure[0, 0].add_image(data=data, name="iio camera") -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/image/image_vminvmax.py b/examples/desktop/image/image_vminvmax.py index d24d1f18c..d9e49b18e 100644 --- a/examples/desktop/image/image_vminvmax.py +++ b/examples/desktop/image/image_vminvmax.py @@ -1,32 +1,34 @@ """ -Simple Plot -============ +Image Vmin/Vmax +=============== + Example showing the simple plot creation followed by changing the vmin/vmax with Standard imageio image. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import imageio.v3 as iio - -fig = fpl.Figure() +figure = fpl.Figure() data = iio.imread("imageio:astronaut.png") # plot the image data -image_graphic = fig[0, 0].add_image(data=data, name="iio astronaut") +image_graphic = figure[0, 0].add_image(data=data, name="iio astronaut") -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) -fig[0, 0].auto_scale() +figure[0, 0].auto_scale() image_graphic.vmin = 0.5 image_graphic.vmax = 0.75 - +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/image/image_widget.py b/examples/desktop/image/image_widget.py index 80aafe0b1..de1d27de1 100644 --- a/examples/desktop/image/image_widget.py +++ b/examples/desktop/image/image_widget.py @@ -1,19 +1,22 @@ """ Image widget ============ + Example showing the image widget in action. When run in a notebook, or with the Qt GUI backend, sliders are also shown. """ +# sphinx_gallery_pygfx_docs = 'hidden' + import fastplotlib as fpl import imageio.v3 as iio # not a fastplotlib dependency, only used for examples - a = iio.imread("imageio:camera.png") iw = fpl.ImageWidget(data=a, cmap="viridis") iw.show() - +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line/README.rst b/examples/desktop/line/README.rst new file mode 100644 index 000000000..b9970c543 --- /dev/null +++ b/examples/desktop/line/README.rst @@ -0,0 +1,2 @@ +Line Examples +============= diff --git a/examples/desktop/line/__init__.py b/examples/desktop/line/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/desktop/line/line.py b/examples/desktop/line/line.py index 56575a810..cd661da1e 100644 --- a/examples/desktop/line/line.py +++ b/examples/desktop/line/line.py @@ -1,16 +1,17 @@ """ -Line Plot -============ +Simple Line Plot +================ + Example showing cosine, sine, sinc lines. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(-10, 10, 100) # sine wave @@ -26,22 +27,23 @@ ys = np.sinc(xs) * 3 + 8 sinc = np.dstack([xs, ys])[0] -sine_graphic = fig[0, 0].add_line(data=sine, thickness=5, colors="magenta") +sine_graphic = figure[0, 0].add_line(data=sine, thickness=5, colors="magenta") # you can also use colormaps for lines! -cosine_graphic = fig[0, 0].add_line(data=cosine, thickness=12, cmap="autumn") +cosine_graphic = figure[0, 0].add_line(data=cosine, thickness=12, cmap="autumn") # or a list of colors for each datapoint colors = ["r"] * 25 + ["purple"] * 25 + ["y"] * 25 + ["b"] * 25 -sinc_graphic = fig[0, 0].add_line(data=sinc, thickness=5, colors=colors) - -fig.show() +sinc_graphic = figure[0, 0].add_line(data=sinc, thickness=5, colors=colors) -fig.canvas.set_logical_size(800, 800) +figure.show() -fig[0, 0].auto_scale() +figure.canvas.set_logical_size(700, 560) +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line/line_cmap.py b/examples/desktop/line/line_cmap.py index f18ceb201..5ffea6fef 100644 --- a/examples/desktop/line/line_cmap.py +++ b/examples/desktop/line/line_cmap.py @@ -1,16 +1,17 @@ """ -Line Plot -============ +Line Plot Colormap +================== + Example showing cosine, sine, sinc lines. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(-10, 10, 100) # sine wave @@ -22,7 +23,7 @@ cosine = np.dstack([xs, ys])[0] # cmap_transform from an array, so the colors on the sine line will be based on the sine y-values -sine_graphic = fig[0, 0].add_line( +sine_graphic = figure[0, 0].add_line( data=sine, thickness=10, cmap="plasma", @@ -31,17 +32,19 @@ # qualitative colormaps, useful for cluster labels or other types of categorical labels labels = [0] * 25 + [5] * 10 + [1] * 35 + [2] * 30 -cosine_graphic = fig[0, 0].add_line( +cosine_graphic = figure[0, 0].add_line( data=cosine, thickness=10, cmap="tab10", cmap_transform=labels ) -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line/line_colorslice.py b/examples/desktop/line/line_colorslice.py index 28b877793..3d18d74b7 100644 --- a/examples/desktop/line/line_colorslice.py +++ b/examples/desktop/line/line_colorslice.py @@ -1,16 +1,17 @@ """ -Line Plot -========= +Line Plot Color Slicing +======================= + Example showing color slicing with cosine, sine, sinc lines. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(-10, 10, 100) # sine wave @@ -26,14 +27,14 @@ ys = np.sinc(xs) * 3 sinc = np.column_stack([xs, ys]) -sine_graphic = fig[0, 0].add_line( +sine_graphic = figure[0, 0].add_line( data=sine, thickness=5, colors="magenta" ) # you can also use colormaps for lines! -cosine_graphic = fig[0, 0].add_line( +cosine_graphic = figure[0, 0].add_line( data=cosine, thickness=12, cmap="autumn", @@ -42,7 +43,7 @@ # or a list of colors for each datapoint colors = ["r"] * 25 + ["purple"] * 25 + ["y"] * 25 + ["b"] * 25 -sinc_graphic = fig[0, 0].add_line( +sinc_graphic = figure[0, 0].add_line( data=sinc, thickness=5, colors=colors, @@ -51,14 +52,14 @@ zeros = np.zeros(xs.size) zeros_data = np.column_stack([xs, zeros]) -zeros_graphic = fig[0, 0].add_line( +zeros_graphic = figure[0, 0].add_line( data=zeros_data, thickness=8, colors="w", offset=(0, 10, 0) ) -fig.show() +figure.show() # indexing of colors cosine_graphic.colors[:15] = "magenta" @@ -81,11 +82,12 @@ zeros_graphic.cmap[50:75] = "jet" zeros_graphic.cmap[75:] = "viridis" -fig.canvas.set_logical_size(800, 800) - -fig[0, 0].auto_scale() +figure.canvas.set_logical_size(700, 560) +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line/line_dataslice.py b/examples/desktop/line/line_dataslice.py index c2c6b9d36..eac765c68 100644 --- a/examples/desktop/line/line_dataslice.py +++ b/examples/desktop/line/line_dataslice.py @@ -1,16 +1,17 @@ """ -Line Plot -============ +Line Plot Data Slicing +====================== + Example showing data slicing with cosine, sine, sinc lines. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np - -fig = fpl.Figure() +figure = fpl.Figure() xs = np.linspace(-10, 10, 100) # sine wave @@ -26,16 +27,16 @@ ys = np.sinc(xs) * 3 + 8 sinc = np.dstack([xs, ys])[0] -sine_graphic = fig[0, 0].add_line(data=sine, thickness=5, colors="magenta") +sine_graphic = figure[0, 0].add_line(data=sine, thickness=5, colors="magenta") # you can also use colormaps for lines! -cosine_graphic = fig[0, 0].add_line(data=cosine, thickness=12, cmap="autumn") +cosine_graphic = figure[0, 0].add_line(data=cosine, thickness=12, cmap="autumn") # or a list of colors for each datapoint colors = ["r"] * 25 + ["purple"] * 25 + ["y"] * 25 + ["b"] * 25 -sinc_graphic = fig[0, 0].add_line(data=sinc, thickness=5, colors=colors) +sinc_graphic = figure[0, 0].add_line(data=sinc, thickness=5, colors=colors) -fig.show() +figure.show() cosine_graphic.data[10:50:5, :2] = sine[10:50:5] cosine_graphic.data[90:, 1] = 7 @@ -45,11 +46,12 @@ bool_key = [True, True, True, False, False] * 20 sinc_graphic.data[bool_key, 1] = 7 # y vals to 1 -fig.canvas.set_logical_size(800, 800) - -fig[0, 0].auto_scale() +figure.canvas.set_logical_size(700, 560) +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line_collection/README.rst b/examples/desktop/line_collection/README.rst new file mode 100644 index 000000000..3dbe05f7f --- /dev/null +++ b/examples/desktop/line_collection/README.rst @@ -0,0 +1,2 @@ +LineCollection Examples +======================= diff --git a/examples/desktop/line_collection/__init__.py b/examples/desktop/line_collection/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/desktop/line_collection/line_collection.py b/examples/desktop/line_collection/line_collection.py index db99e32ed..44b765319 100644 --- a/examples/desktop/line_collection/line_collection.py +++ b/examples/desktop/line_collection/line_collection.py @@ -1,10 +1,12 @@ """ -Line collection -=============== +Line Collection Simple +====================== + Example showing how to plot line collections """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' from itertools import product import numpy as np @@ -27,14 +29,16 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray: pos_xy = np.vstack(circles) -fig = fpl.Figure() +figure = fpl.Figure() -fig[0, 0].add_line_collection(circles, cmap="jet", thickness=5) +figure[0, 0].add_line_collection(circles, cmap="jet", thickness=5) -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line_collection/line_collection_cmap_values.py b/examples/desktop/line_collection/line_collection_cmap_values.py index 5ffc032e9..e94a161ad 100644 --- a/examples/desktop/line_collection/line_collection_cmap_values.py +++ b/examples/desktop/line_collection/line_collection_cmap_values.py @@ -1,16 +1,17 @@ """ Line collections quantitative cmap ================================== + Example showing a line collection with a quantitative cmap """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' from itertools import product import numpy as np import fastplotlib as fpl - def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray: theta = np.linspace(0, 2 * np.pi, n_points) xs = radius * np.sin(theta) @@ -33,16 +34,18 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray: # highest values, lowest values, mid-high values, mid values cmap_values = [10] * 4 + [0] * 4 + [7] * 4 + [5] * 4 -fig = fpl.Figure() +figure = fpl.Figure() -fig[0, 0].add_line_collection( +figure[0, 0].add_line_collection( circles, cmap="bwr", cmap_transform=cmap_values, thickness=10 ) -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line_collection/line_collection_cmap_values_qualitative.py b/examples/desktop/line_collection/line_collection_cmap_values_qualitative.py index f96fd3aac..5f9ea0000 100644 --- a/examples/desktop/line_collection/line_collection_cmap_values_qualitative.py +++ b/examples/desktop/line_collection/line_collection_cmap_values_qualitative.py @@ -1,16 +1,17 @@ """ -Line collections qualitative cmaps -================================== +Line Collection Qualitative Colormap +==================================== + Example showing a line collection with a qualitative cmap """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' from itertools import product import numpy as np import fastplotlib as fpl - def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray: theta = np.linspace(0, 2 * np.pi, n_points) xs = radius * np.sin(theta) @@ -39,19 +40,21 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray: 1, 1, 1, 5 ] -fig = fpl.Figure() +figure = fpl.Figure() -fig[0, 0].add_line_collection( +figure[0, 0].add_line_collection( circles, cmap="tab10", cmap_transform=cmap_values, thickness=10 ) -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line_collection/line_collection_colors.py b/examples/desktop/line_collection/line_collection_colors.py index 3ee561d8f..bf3e818cd 100644 --- a/examples/desktop/line_collection/line_collection_colors.py +++ b/examples/desktop/line_collection/line_collection_colors.py @@ -1,10 +1,12 @@ """ -Line collection colors +Line Collection Colors ====================== + Example showing one way ot setting colors for individual lines in a collection """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' from itertools import product import numpy as np @@ -31,14 +33,16 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray: # this will produce 16 circles so we will define 16 colors colors = ["blue"] * 4 + ["red"] * 4 + ["yellow"] * 4 + ["w"] * 4 -fig = fpl.Figure() +figure = fpl.Figure() -fig[0, 0].add_line_collection(circles, colors=colors, thickness=10) +figure[0, 0].add_line_collection(circles, colors=colors, thickness=10) -fig.show() +figure.show() -fig.canvas.set_logical_size(800, 800) +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line_collection/line_collection_slicing.py b/examples/desktop/line_collection/line_collection_slicing.py index 9eaebdd7e..a7525f7ba 100644 --- a/examples/desktop/line_collection/line_collection_slicing.py +++ b/examples/desktop/line_collection/line_collection_slicing.py @@ -1,10 +1,12 @@ """ Line collection slicing ======================= + Example showing how to slice a line collection """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import numpy as np import fastplotlib as fpl @@ -18,9 +20,9 @@ multi_data = np.stack([data] * 15) -fig = fpl.Figure() +figure = fpl.Figure() -lines = fig[0, 0].add_line_stack( +lines = figure[0, 0].add_line_stack( multi_data, thickness=[2, 10, 2, 5, 5, 5, 8, 8, 8, 9, 3, 3, 3, 4, 4], separation=1, @@ -59,9 +61,9 @@ lines[::2].colors[::5] = "magenta" # set every 5th point of every other line to magenta lines[3:6].colors[50:, -1] = 0.6 # set half the points alpha to 0.6 -fig.show(maintain_aspect=False) +figure.show(maintain_aspect=False) -fig.canvas.set_logical_size(900, 600) +figure.canvas.set_logical_size(700, 580) if __name__ == "__main__": print(__doc__) diff --git a/examples/desktop/line_collection/line_stack.py b/examples/desktop/line_collection/line_stack.py index 676e6e5c2..e7f7125e1 100644 --- a/examples/desktop/line_collection/line_stack.py +++ b/examples/desktop/line_collection/line_stack.py @@ -1,10 +1,12 @@ """ -Line stack +Line Stack ========== + Example showing how to plot a stack of lines """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' import numpy as np import fastplotlib as fpl @@ -17,19 +19,21 @@ data = np.column_stack([xs, ys]) multi_data = np.stack([data] * 10) -fig = fpl.Figure() +figure = fpl.Figure() -line_stack = fig[0, 0].add_line_stack( +line_stack = figure[0, 0].add_line_stack( multi_data, # shape: (10, 100, 2), i.e. [n_lines, n_points, xy] cmap="jet", # applied along n_lines thickness=5, separation=1, # spacing between lines along the separation axis, default separation along "y" axis ) -fig.show(maintain_aspect=False) +figure.show(maintain_aspect=False) -fig.canvas.set_logical_size(900, 600) +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/line_collection/line_stack_3d.py b/examples/desktop/line_collection/line_stack_3d.py index 41914e2d2..314a97ff2 100644 --- a/examples/desktop/line_collection/line_stack_3d.py +++ b/examples/desktop/line_collection/line_stack_3d.py @@ -1,10 +1,12 @@ """ Line stack 3D ============= + Example showing a 3D stack of lines with animations """ # test_example = false +# sphinx_gallery_pygfx_docs = 'animate' import numpy as np import fastplotlib as fpl @@ -19,9 +21,9 @@ multi_data = np.stack([data] * 10) # create figure to plot lines and use an orbit controller in 3D -fig = fpl.Figure(cameras="3d", controller_types="orbit") +figure = fpl.Figure(cameras="3d", controller_types="orbit") -line_stack = fig[0, 0].add_line_stack( +line_stack = figure[0, 0].add_line_stack( multi_data, # shape: (10, 100, 2), i.e. [n_lines, n_points, xy] cmap="jet", # applied along n_lines thickness=3, @@ -75,7 +77,7 @@ def animate_colors(subplot): colors_iteration += 1 -fig[0, 0].add_animations(animate_data, animate_colors) +figure[0, 0].add_animations(animate_data, animate_colors) # just a pre-saved camera state camera_state = { @@ -91,13 +93,14 @@ def animate_colors(subplot): "depth_range": None, } -fig.show(maintain_aspect=False) - -fig[0, 0].camera.set_state(camera_state) +figure.show(maintain_aspect=False) -fig.canvas.set_logical_size(500, 500) +figure[0, 0].camera.set_state(camera_state) +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/misc/README.rst b/examples/desktop/misc/README.rst new file mode 100644 index 000000000..cc51fd686 --- /dev/null +++ b/examples/desktop/misc/README.rst @@ -0,0 +1,2 @@ +Other Examples +============== diff --git a/examples/desktop/misc/cycle_animation.py b/examples/desktop/misc/cycle_animation.py new file mode 100644 index 000000000..bb402a1f7 --- /dev/null +++ b/examples/desktop/misc/cycle_animation.py @@ -0,0 +1,62 @@ +""" +Scatter Animation Colors +======================== + +Example showing animation with a scatter plot. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'animate' + +import fastplotlib as fpl +import numpy as np + +# create a random distribution of 10,000 xyz coordinates +n_points = 10_000 + +# dimensions always have to be [n_points, xyz] +dims = (n_points, 3) + +clouds_offset = 15 + +# create some random clouds +normal = np.random.normal(size=dims, scale=5) +# stack the data into a single array +cloud = np.vstack( + [ + normal - clouds_offset, + normal, + normal + clouds_offset, + ] +) + +# color each of them separately +colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points + +# create plot +figure = fpl.Figure() +subplot_scatter = figure[0, 0] +# use an alpha value since this will be a lot of points +scatter_graphic = subplot_scatter.add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6) + + +i = 0.05 +def cycle_colors(subplot): + global i + # cycle the red values + scatter_graphic.colors[n_points * 2:, 0] = np.abs(np.sin(i)) + scatter_graphic.colors[n_points * 2:, 1] = np.abs(np.sin(i + (np.pi / 4))) + scatter_graphic.colors[n_points * 2:, 2] = np.abs(np.cos(i)) + i += 0.05 + +subplot_scatter.add_animations(cycle_colors) + +figure.show() + +subplot_scatter.canvas.set_logical_size(700, 560) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() \ No newline at end of file diff --git a/examples/desktop/misc/em_wave_animation.py b/examples/desktop/misc/em_wave_animation.py new file mode 100644 index 000000000..50ab27ed6 --- /dev/null +++ b/examples/desktop/misc/em_wave_animation.py @@ -0,0 +1,105 @@ +""" +Electromagnetic Wave Animation +============================== + +Example showing animation of an electromagnetic wave. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'animate' + +import fastplotlib as fpl +import numpy as np + +figure = fpl.Figure( + cameras="3d", + controller_types="orbit", + size=(700, 400) +) + +start, stop = 0, 4 * np.pi + +# let's define the x, y and z axes for each with direction of wave propogation along the z-axis +# electric field in the xz plane travelling along +zs = np.linspace(start, stop, 200) +e_ys = np.zeros(200) +e_xs = np.sin(zs) +electric = np.column_stack([e_xs, e_ys, zs]) + +# magnetic field in the yz plane +zs = np.linspace(start, stop, 200) +m_ys = np.sin(zs) +m_xs = np.zeros(200) +magnetic = np.column_stack([m_xs, m_ys, zs]) + +# add the lines +figure[0, 0].add_line(electric, colors="blue", thickness=2, name="e") +figure[0, 0].add_line(magnetic, colors="red", thickness=2, name="m") + +# draw vector line at every 10th position +electric_vectors = [np.array([[0, 0, z], [x, 0, z]]) for (x, z) in zip(e_xs[::10], zs[::10])] +magnetic_vectors = [np.array([[0, 0, z], [0, y, z]]) for (y, z) in zip(m_ys[::10], zs[::10])] + +# add as a line collection +figure[0, 0].add_line_collection(electric_vectors, colors="blue", thickness=1.5, name="e-vec") +figure[0, 0].add_line_collection(magnetic_vectors, colors="red", thickness=1.5, name="m-vec") +# note that the z_offset in `add_line_collection` is not data-related +# it is the z-offset for where to place the *graphic*, by default with Orthographic cameras (i.e. 2D views) +# it will increment by 1 for each line in the collection, we want to disable this so set z_position=0 + +# axes are a WIP, just draw a white line along z for now +z_axis = np.array([[0, 0, 0], [0, 0, stop]]) +figure[0, 0].add_line(z_axis, colors="w", thickness=1) + +# just a pre-saved camera state +state = { + 'position': np.array([-8.0 , 6.0, -2.0]), + 'rotation': np.array([0.09, 0.9 , 0.2, -0.5]), + 'scale': np.array([1., 1., 1.]), + 'reference_up': np.array([0., 1., 0.]), + 'fov': 50.0, + 'width': 12, + 'height': 12, + 'zoom': 1.35, + 'maintain_aspect': True, + 'depth_range': None +} + + +figure[0, 0].camera.set_state(state) + +figure.show() + +figure[0, 0].camera.zoom = 1.5 + +increment = np.pi * 4 / 100 + +figure.canvas.set_logical_size(700, 560) + +# moves the wave one step along the z-axis +def tick(subplot): + global increment, start, stop, zs + new_zs = np.linspace(start, stop, 200) + new_data = np.sin(new_zs) + + # just change the x-axis vals for the electric field + subplot["e"].data[:, 0] = new_data + # and y-axis vals for magnetic field + subplot["m"].data[:, 1] = new_data + + # update the vector lines + for i, (value, z) in enumerate(zip(new_data[::10], zs[::10])): + subplot["e-vec"].graphics[i].data = np.array([[0, 0, z], [value, 0, z]]) + subplot["m-vec"].graphics[i].data = np.array([[0, 0, z], [0, value, z]]) + + start += increment + stop += increment + + +figure[0, 0].add_animations(tick) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() \ No newline at end of file diff --git a/examples/desktop/misc/image_animation.py b/examples/desktop/misc/image_animation.py new file mode 100644 index 000000000..df84f3c5a --- /dev/null +++ b/examples/desktop/misc/image_animation.py @@ -0,0 +1,38 @@ +""" +Simple Image Update +=================== + +Example showing updating a single plot with new random 512x512 data. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'animate' + +import fastplotlib as fpl +import numpy as np + +data = np.random.rand(512, 512) + +figure = fpl.Figure() + +# plot the image data +image_graphic = figure[0, 0].add_image(data=data, name="random-image") + + +# a function to update the image_graphic +# a figure-level animation function will optionally take the figure as an argument +def update_data(figure_instance): + new_data = np.random.rand(512, 512) + figure_instance[0, 0]["random-image"].data = new_data + +figure.add_animations(update_data) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() diff --git a/examples/desktop/misc/line3d_animation.py b/examples/desktop/misc/line3d_animation.py new file mode 100644 index 000000000..27d22c78a --- /dev/null +++ b/examples/desktop/misc/line3d_animation.py @@ -0,0 +1,59 @@ +""" +Simple 3D Line Animation +======================== + +Example showing animation with 3D lines. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'animate 5s' + +import numpy as np +import fastplotlib as fpl + +# create data in the shape of a spiral +phi = np.linspace(0, 30, 200) + +xs = phi * np.cos(phi) +ys = phi * np.sin(phi) +zs = phi + +# make data 3d, with shape [, 3] +spiral = np.dstack([xs, ys, zs])[0] + +figure = fpl.Figure(cameras="3d") + +line_graphic = figure[0,0].add_line(data=spiral, thickness=3, cmap='jet') + +marker = figure[0,0].add_scatter(data=spiral[0], sizes=10, name="marker") + +marker_index = 0 + + +# a function to move the ball along the spiral +def move_marker(): + global marker_index + + marker_index += 1 + + if marker_index == spiral.shape[0]: + marker_index = 0 + + for subplot in figure: + subplot["marker"].data = spiral[marker_index] + + +# add `move_marker` to the animations +figure.add_animations(move_marker) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +figure[0,0].auto_scale(maintain_aspect=False) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() diff --git a/examples/desktop/misc/line_animation.py b/examples/desktop/misc/line_animation.py new file mode 100644 index 000000000..50faad5c7 --- /dev/null +++ b/examples/desktop/misc/line_animation.py @@ -0,0 +1,53 @@ +""" +Simple Line Animation +===================== + +Example showing animation with lines. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'animate' + +import fastplotlib as fpl +import numpy as np + +# generate some data +start, stop = 0, 2 * np.pi +increment = (2 * np.pi) / 50 + +# make a simple sine wave +xs = np.linspace(start, stop, 100) +ys = np.sin(xs) + +figure = fpl.Figure() + +# plot the image data +sine = figure[0, 0].add_line(ys, name="sine", colors="r") + + +# increment along the x-axis on each render loop :D +def update_line(subplot): + global increment, start, stop + xs = np.linspace(start + increment, stop + increment, 100) + ys = np.sin(xs) + + start += increment + stop += increment + + # change only the y-axis values of the line + subplot["sine"].data[:, 1] = ys + + +figure[0, 0].add_animations(update_line) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +figure[0,0].auto_scale(maintain_aspect=False) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() \ No newline at end of file diff --git a/examples/desktop/misc/multiplot_animation.py b/examples/desktop/misc/multiplot_animation.py new file mode 100644 index 000000000..a712ce9ef --- /dev/null +++ b/examples/desktop/misc/multiplot_animation.py @@ -0,0 +1,49 @@ +""" +Multi-Subplot Image Update +========================== + +Example showing updating a single plot with new random 512x512 data. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'animate' + +import fastplotlib as fpl +import numpy as np + +# Figure of shape 2 x 3 with all controllers synced +figure = fpl.Figure(shape=(2, 3), controller_ids="sync") + +# Make a random image graphic for each subplot +for subplot in figure: + # create image data + data = np.random.rand(512, 512) + # add an image to the subplot + subplot.add_image(data, name="rand-img") + +figure[0,1]["rand-img"].cmap = "viridis" +figure[1,0]["rand-img"].cmap = "Wistia" +figure[0,2]["rand-img"].cmap = "gray" +figure[1,1]["rand-img"].cmap = "spring" + +# Define a function to update the image graphics with new data +# add_animations will pass the gridplot to the animation function +def update_data(f): + for subplot in f: + new_data = np.random.rand(512, 512) + # index the image graphic by name and set the data + subplot["rand-img"].data = new_data + +# add the animation function +figure.add_animations(update_data) + +# show the gridplot +figure.show() + +figure.canvas.set_logical_size(700, 560) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() \ No newline at end of file diff --git a/examples/desktop/misc/scatter_animation.py b/examples/desktop/misc/scatter_animation.py new file mode 100644 index 000000000..aa1495dd9 --- /dev/null +++ b/examples/desktop/misc/scatter_animation.py @@ -0,0 +1,59 @@ +""" +Scatter Animation Data +====================== + +Example showing animation with a scatter plot. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'animate' + +import fastplotlib as fpl +import numpy as np + +# create a random distribution of 10,000 xyz coordinates +n_points = 10_000 + +# dimensions always have to be [n_points, xyz] +dims = (n_points, 3) + +clouds_offset = 15 + +# create some random clouds +normal = np.random.normal(size=dims, scale=5) +# stack the data into a single array +cloud = np.vstack( + [ + normal - clouds_offset, + normal, + normal + clouds_offset, + ] +) + +# color each of them separately +colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points + +# create plot +figure = fpl.Figure() +subplot_scatter = figure[0, 0] +# use an alpha value since this will be a lot of points +scatter_graphic = subplot_scatter.add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6) + + +def update_points(subplot): + # move every point by a small amount + deltas = np.random.normal(size=scatter_graphic.data.value.shape, loc=0, scale=0.15) + scatter_graphic.data = scatter_graphic.data.value + deltas + + +subplot_scatter.add_animations(update_points) + +figure.show() + +subplot_scatter.canvas.set_logical_size(700, 560) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() \ No newline at end of file diff --git a/examples/desktop/misc/simple_event.py b/examples/desktop/misc/simple_event.py new file mode 100644 index 000000000..b6d408862 --- /dev/null +++ b/examples/desktop/misc/simple_event.py @@ -0,0 +1,56 @@ +""" +Simple Event +============ + +Example showing how to add a simple callback event. +""" + +# test_example = false +# sphinx_gallery_pygfx_docs = 'screenshot' + +import fastplotlib as fpl +import imageio.v3 as iio + +data = iio.imread("imageio:camera.png") + +# Create a figure +figure = fpl.Figure() + +# plot sine wave, use a single color +image_graphic = figure[0,0].add_image(data=data) + +# show the plot +figure.show() + + +# define callback function to print the event data +def callback_func(event_data): + print(event_data.info) + + +# Will print event data when the color changes +image_graphic.add_event_handler(callback_func, "cmap") + +image_graphic.cmap = "viridis" + + +# adding a click event, we can also use decorators to add event handlers +@image_graphic.add_event_handler("click") +def click_event(event_data): + # get the click location in screen coordinates + xy = (event_data.x, event_data.y) + + # map the screen coordinates to world coordinates + xy = figure[0,0].map_screen_to_world(xy)[:-1] + + # print the click location + print(xy) + + +figure.canvas.set_logical_size(700, 560) + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() diff --git a/examples/desktop/scatter/README.rst b/examples/desktop/scatter/README.rst new file mode 100644 index 000000000..278170fb4 --- /dev/null +++ b/examples/desktop/scatter/README.rst @@ -0,0 +1,2 @@ +Scatter Examples +================ diff --git a/examples/desktop/scatter/__init__.py b/examples/desktop/scatter/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/desktop/scatter/scatter.py b/examples/desktop/scatter/scatter.py index c47306722..05dd7a99b 100644 --- a/examples/desktop/scatter/scatter.py +++ b/examples/desktop/scatter/scatter.py @@ -1,32 +1,54 @@ """ Scatter Plot ============ + Example showing scatter plot. """ -# test_example = true +# test_example = false +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np -from pathlib import Path -fig = fpl.Figure() +figure = fpl.Figure() + +# create a random distribution of 10,000 xyz coordinates +n_points = 5_000 + +# dimensions always have to be [n_points, xyz] +dims = (n_points, 3) + +clouds_offset = 15 -data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy") -data = np.load(data_path) +# create some random clouds +normal = np.random.normal(size=dims, scale=5) +# stack the data into a single array +cloud = np.vstack( + [ + normal - clouds_offset, + normal, + normal + clouds_offset, + ] +) -n_points = 50 +# color each of them separately colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points -scatter_graphic = fig[0, 0].add_scatter(data=data[:, :-1], sizes=6, alpha=0.7, colors=colors) +# create plot +figure = fpl.Figure() -fig.show() +# use an alpha value since this will be a lot of points +figure[0,0].add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6) -fig.canvas.set_logical_size(800, 800) +figure.show() -fig[0, 0].auto_scale() +figure.canvas.set_logical_size(700, 560) +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/scatter/scatter_cmap.py b/examples/desktop/scatter/scatter_cmap.py index 58c43c0ea..0adf72509 100644 --- a/examples/desktop/scatter/scatter_cmap.py +++ b/examples/desktop/scatter/scatter_cmap.py @@ -1,42 +1,53 @@ """ -Scatter Plot -============ +Scatter Colormap +================ + Example showing cmap change for scatter plot. """ -# test_example = true +# test_example = false +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np -from pathlib import Path -from sklearn.cluster import AgglomerativeClustering +figure = fpl.Figure() -fig = fpl.Figure() +# create a random distribution of 10,000 xyz coordinates +n_points = 5_000 -data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy") -data = np.load(data_path) +# dimensions always have to be [n_points, xyz] +dims = (n_points, 3) -agg = AgglomerativeClustering(n_clusters=3) -agg.fit_predict(data) +clouds_offset = 15 -scatter_graphic = fig[0, 0].add_scatter( - data=data[:, :-1], # use only xy data - sizes=15, - alpha=0.7, - cmap="Set1", - cmap_transform=agg.labels_ # use the labels as a transform to map colors from the colormap +# create some random clouds +normal = np.random.normal(size=dims, scale=5) +# stack the data into a single array +cloud = np.vstack( + [ + normal - clouds_offset, + normal, + normal + clouds_offset, + ] ) -fig.show() +# color each of them separately +colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points + +# use an alpha value since this will be a lot of points +figure[0,0].add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6) -fig.canvas.set_logical_size(800, 800) +figure.show() -fig[0, 0].auto_scale() +figure[0,0].graphics[0].cmap = "viridis" -scatter_graphic.cmap = "tab10" +figure.canvas.set_logical_size(700, 560) +figure[0, 0].auto_scale() +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/scatter/scatter_cmap_iris.py b/examples/desktop/scatter/scatter_cmap_iris.py new file mode 100644 index 000000000..700f5c136 --- /dev/null +++ b/examples/desktop/scatter/scatter_cmap_iris.py @@ -0,0 +1,42 @@ +""" +Iris Scatter Colormap +===================== + +Example showing cmap change for scatter plot. +""" + +# test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' + +import fastplotlib as fpl +from sklearn.cluster import AgglomerativeClustering +from sklearn import datasets + + +figure = fpl.Figure() + +data = datasets.load_iris()["data"] + +agg = AgglomerativeClustering(n_clusters=3) +agg.fit_predict(data) + +scatter_graphic = figure[0, 0].add_scatter( + data=data[:, :-1], # use only xy data + sizes=15, + alpha=0.7, + cmap="Set1", + cmap_transform=agg.labels_ # use the labels as a transform to map colors from the colormap +) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +figure[0, 0].auto_scale() + +scatter_graphic.cmap = "tab10" + + +if __name__ == "__main__": + print(__doc__) + fpl.run() diff --git a/examples/desktop/scatter/scatter_colorslice.py b/examples/desktop/scatter/scatter_colorslice.py index 60433b5f5..3d3a3fa26 100644 --- a/examples/desktop/scatter/scatter_colorslice.py +++ b/examples/desktop/scatter/scatter_colorslice.py @@ -1,42 +1,60 @@ """ -Scatter Plot -============ +Scatter Plot Color Slicing +========================== + Example showing color slice for scatter plot. """ -# test_example = true +# test_example = false +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np -from pathlib import Path +figure = fpl.Figure() -fig = fpl.Figure() +# create a random distribution of 10,000 xyz coordinates +n_points = 5_000 -data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy") -data = np.load(data_path) +# dimensions always have to be [n_points, xyz] +dims = (n_points, 3) -n_points = 50 -colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points +clouds_offset = 30 -scatter_graphic = fig[0, 0].add_scatter( - data=data[:, :-1], - sizes=6, - alpha=0.7, - colors=colors # use colors from the list of strings +# create some random clouds +normal = np.random.normal(size=dims, scale=5) +# stack the data into a single array +cloud = np.vstack( + [ + normal - clouds_offset, + normal, + normal + clouds_offset, + ] ) -fig.show() +# color each of them separately +colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points + +# create plot +figure = fpl.Figure() -fig.canvas.set_logical_size(800, 800) +# use an alpha value since this will be a lot of points +figure[0,0].add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6) -fig[0, 0].auto_scale() +figure.show() + +figure.canvas.set_logical_size(700, 560) + +scatter_graphic = figure[0, 0].graphics[0] + +figure[0, 0].auto_scale() scatter_graphic.colors[0:75] = "red" scatter_graphic.colors[75:150] = "white" scatter_graphic.colors[::2] = "blue" - +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/scatter/scatter_colorslice_iris.py b/examples/desktop/scatter/scatter_colorslice_iris.py new file mode 100644 index 000000000..a1e6d5318 --- /dev/null +++ b/examples/desktop/scatter/scatter_colorslice_iris.py @@ -0,0 +1,42 @@ +""" +Iris Scatter Plot Color Slicing +=============================== + +Example showing color slice for scatter plot. +""" + +# test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' + +import fastplotlib as fpl +from sklearn import datasets + + +figure = fpl.Figure() + +data = datasets.load_iris()["data"] + +n_points = 50 +colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points + +scatter_graphic = figure[0, 0].add_scatter( + data=data[:, :-1], + sizes=6, + alpha=0.7, + colors=colors # use colors from the list of strings +) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +figure[0, 0].auto_scale() + +scatter_graphic.colors[0:75] = "red" +scatter_graphic.colors[75:150] = "white" +scatter_graphic.colors[::2] = "blue" + + +if __name__ == "__main__": + print(__doc__) + fpl.run() diff --git a/examples/desktop/scatter/scatter_dataslice.py b/examples/desktop/scatter/scatter_dataslice.py index 989b7c21c..af2fffebd 100644 --- a/examples/desktop/scatter/scatter_dataslice.py +++ b/examples/desktop/scatter/scatter_dataslice.py @@ -1,40 +1,46 @@ """ -Scatter Plot -============ +Scatter Plot Data Slicing +========================= + Example showing data slice for scatter plot. """ -# test_example = true +# test_example = false +# sphinx_gallery_pygfx_docs = 'screenshot' import fastplotlib as fpl import numpy as np -from pathlib import Path -fig = fpl.Figure() +figure = fpl.Figure() -data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy") -data = np.load(data_path) +# create a gaussian cloud of 5_000 points +n_points = 1_000 -n_points = 50 -colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points +mean = [0, 0] # mean of the Gaussian distribution +covariance = [[1, 0], [0, 1]] # covariance matrix -scatter_graphic = fig[0, 0].add_scatter(data=data[:, :-1], sizes=6, alpha=0.7, colors=colors) +gaussian_cloud = np.random.multivariate_normal(mean, covariance, n_points) +gaussian_cloud2 = np.random.multivariate_normal(mean, covariance, n_points) -fig.show() +# create plot +figure = fpl.Figure() -fig.canvas.set_logical_size(800, 800) +# use an alpha value since this will be a lot of points +scatter1 = figure[0,0].add_scatter(data=gaussian_cloud, sizes=3) +scatter2 = figure[0,0].add_scatter(data=gaussian_cloud2, colors="r", sizes=3) -fig[0, 0].auto_scale() +figure.show() -scatter_graphic.data[0] = np.array([[5, 3, 1.5]]) -scatter_graphic.data[1] = np.array([[4.3, 3.2, 1.3]]) -scatter_graphic.data[2] = np.array([[5.2, 2.7, 1.7]]) +figure.canvas.set_logical_size(700, 560) -scatter_graphic.data[10:15] = scatter_graphic.data[0:5] + np.array([1, 1, 1]) -scatter_graphic.data[50:100:2] = scatter_graphic.data[100:150:2] + np.array([1, 1, 0]) +figure[0, 0].auto_scale() +scatter1.data[:500] = np.array([0 , 0, 0]) +scatter2.data[500:] = np.array([0 , 0, 0]) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/scatter/scatter_dataslice_iris.py b/examples/desktop/scatter/scatter_dataslice_iris.py new file mode 100644 index 000000000..0d47c6efd --- /dev/null +++ b/examples/desktop/scatter/scatter_dataslice_iris.py @@ -0,0 +1,41 @@ +""" +Iris Scatter Plot Data Slicing +============================== + +Example showing data slice for scatter plot. +""" + +# test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' + +import fastplotlib as fpl +import numpy as np +from sklearn import datasets + + +figure = fpl.Figure() + +data = datasets.load_iris()["data"] + +n_points = 50 +colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points + +scatter_graphic = figure[0, 0].add_scatter(data=data[:, :-1], sizes=6, alpha=0.7, colors=colors) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +figure[0, 0].auto_scale() + +scatter_graphic.data[0] = np.array([[5, 3, 1.5]]) +scatter_graphic.data[1] = np.array([[4.3, 3.2, 1.3]]) +scatter_graphic.data[2] = np.array([[5.2, 2.7, 1.7]]) + +scatter_graphic.data[10:15] = scatter_graphic.data[0:5] + np.array([1, 1, 1]) +scatter_graphic.data[50:100:2] = scatter_graphic.data[100:150:2] + np.array([1, 1, 0]) + + +if __name__ == "__main__": + print(__doc__) + fpl.run() diff --git a/examples/desktop/scatter/scatter_iris.py b/examples/desktop/scatter/scatter_iris.py new file mode 100644 index 000000000..c16a4b135 --- /dev/null +++ b/examples/desktop/scatter/scatter_iris.py @@ -0,0 +1,38 @@ +""" +Iris Scatter Plot +================= + +Example showing scatter plot using sklearn iris dataset. +""" + +# test_example = true +# sphinx_gallery_pygfx_docs = 'hidden' + +import fastplotlib as fpl +import numpy as np +from pathlib import Path +import sys + +figure = fpl.Figure() + +current_file = Path(sys.argv[0]).resolve() + +data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy") +data = np.load(data_path) + +n_points = 50 +colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points + +scatter_graphic = figure[0, 0].add_scatter(data=data[:, :-1], sizes=6, alpha=0.7, colors=colors) + +figure.show() + +figure.canvas.set_logical_size(700, 560) + +figure[0, 0].auto_scale() + +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter +if __name__ == "__main__": + print(__doc__) + fpl.run() \ No newline at end of file diff --git a/examples/desktop/scatter/scatter_size.py b/examples/desktop/scatter/scatter_size.py index 41a97ad53..bd4e2db2b 100644 --- a/examples/desktop/scatter/scatter_size.py +++ b/examples/desktop/scatter/scatter_size.py @@ -1,10 +1,13 @@ """ -Scatter Plot -============ +Scatter Plot Size +================= + Example showing point size change for scatter plot. """ # test_example = true +# sphinx_gallery_pygfx_docs = 'screenshot' + import numpy as np import fastplotlib as fpl @@ -15,7 +18,7 @@ names = [["scalar_size"], ["array_size"]] # Create the grid plot -fig = fpl.Figure(shape=shape, names=names, size=(1000, 1000)) +figure = fpl.Figure(shape=shape, names=names, size=(1000, 1000)) # get y_values using sin function angles = np.arange(0, 20 * np.pi + 0.001, np.pi / 20) @@ -24,18 +27,22 @@ data = np.column_stack([x_values, y_values]) -fig["scalar_size"].add_scatter( +figure["scalar_size"].add_scatter( data=data, sizes=5, colors="blue" ) # add a set of scalar sizes non_scalar_sizes = np.abs((y_values / np.pi)) # ensure minimum size of 5 -fig["array_size"].add_scatter(data=data, sizes=non_scalar_sizes, colors="red") +figure["array_size"].add_scatter(data=data, sizes=non_scalar_sizes, colors="red") -for graph in fig: +for graph in figure: graph.auto_scale(maintain_aspect=True) -fig.show() +figure.show() + +figure.canvas.set_logical_size(700, 560) +# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively +# please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() diff --git a/examples/desktop/screenshots/gridplot.png b/examples/desktop/screenshots/gridplot.png index 9e81fe8c6..6567c57da 100644 --- a/examples/desktop/screenshots/gridplot.png +++ b/examples/desktop/screenshots/gridplot.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:462a06e9c74dc9f0958aa265349dfac9c31d77a3ab3915f85596c85f2e7a6f3a -size 266056 +oid sha256:6499a000911de783b69a7958a1bf2b0290b5a3117fe14ade792baca95557b2a7 +size 263883 diff --git a/examples/desktop/screenshots/gridplot_non_square.png b/examples/desktop/screenshots/gridplot_non_square.png index b74be7065..847ed65cb 100644 --- a/examples/desktop/screenshots/gridplot_non_square.png +++ b/examples/desktop/screenshots/gridplot_non_square.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ab4b1f8188824b81fe29b5c6ac7177734fb2b9958133e19f02919d1da98b96c -size 174978 +oid sha256:e4a0a002caf10e1e80ca0177bac4085e2f837ad3977f2546830acb42f0106f3f +size 173182 diff --git a/examples/desktop/screenshots/heatmap.png b/examples/desktop/screenshots/heatmap.png index ec6cf9955..1adcc1e1d 100644 --- a/examples/desktop/screenshots/heatmap.png +++ b/examples/desktop/screenshots/heatmap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:754bd8713617bf61d1adf57b3e84c1257b038bf15412aa3c8bd466d1405086e7 -size 48524 +oid sha256:3e742d06167a49ec80253cb3984da88e6d623dc645f93bcfbd1a82966ba44a84 +size 40051 diff --git a/examples/desktop/screenshots/heatmap_cmap.png b/examples/desktop/screenshots/heatmap_cmap.png index c495cf72c..cee81dd30 100644 --- a/examples/desktop/screenshots/heatmap_cmap.png +++ b/examples/desktop/screenshots/heatmap_cmap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d2ba0b76e982ceb1439c5ebaabfaf089ea9b09e50934718eaaa29d7492272196 -size 42746 +oid sha256:8863461569f5b89d1443e3051a5512f3987487fcb9e057215d2f030a180fa09f +size 97996 diff --git a/examples/desktop/screenshots/heatmap_data.png b/examples/desktop/screenshots/heatmap_data.png index 229d6c2cc..316a73753 100644 --- a/examples/desktop/screenshots/heatmap_data.png +++ b/examples/desktop/screenshots/heatmap_data.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a7160c4f034214f8052a6d88001dac706b0a85a5a4df076958ba1a176344b85a -size 53854 +oid sha256:a975179e82893dbb04e4674310761e7b02bb62ae6abb1b89397720bddf96ae5f +size 19084 diff --git a/examples/desktop/screenshots/heatmap_square.png b/examples/desktop/screenshots/heatmap_square.png deleted file mode 100644 index 00a01133e..000000000 --- a/examples/desktop/screenshots/heatmap_square.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8d01171b2bd05b5c88df4312c303094fdede36b1cf930455ace6d1fb12d8eb36 -size 81274 diff --git a/examples/desktop/screenshots/heatmap_vmin_vmax.png b/examples/desktop/screenshots/heatmap_vmin_vmax.png index b028291f7..357683d82 100644 --- a/examples/desktop/screenshots/heatmap_vmin_vmax.png +++ b/examples/desktop/screenshots/heatmap_vmin_vmax.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:61c3754de3a7e6622ce1a77dbbf9bbd6ccfd3ccad3b1463b009bf93511258034 -size 44426 +oid sha256:9592f3724016db1b7431bc100b16bec175e197c111e7b442dc2255d51da3f5e8 +size 114957 diff --git a/examples/desktop/screenshots/heatmap_wide.png b/examples/desktop/screenshots/heatmap_wide.png deleted file mode 100644 index 927b933d6..000000000 --- a/examples/desktop/screenshots/heatmap_wide.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:271e0d769b608d0f34a153ab8b8353f1e5d127f239951fc407ccedd3eee5e2e5 -size 82687 diff --git a/examples/desktop/screenshots/image_cmap.png b/examples/desktop/screenshots/image_cmap.png index be16ba213..9ad74e927 100644 --- a/examples/desktop/screenshots/image_cmap.png +++ b/examples/desktop/screenshots/image_cmap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:552a4d5141a5a87baaedd8a9d7d911dfdddee5792c024c77012665268af865e9 -size 189479 +oid sha256:009326a4c3605622980bf80b20cc8cc807fa610858d155304285a1a5d478b56c +size 187517 diff --git a/examples/desktop/screenshots/image_rgb.png b/examples/desktop/screenshots/image_rgb.png index 8d391f07c..50dfe6761 100644 --- a/examples/desktop/screenshots/image_rgb.png +++ b/examples/desktop/screenshots/image_rgb.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:55e76cea92eb34e1e25d730d2533a9a0d845921e78bc980708d320bb353a2d73 -size 218413 +oid sha256:c7e026664f350a4abd83297dc55a324a12ddcf8fd94625d26381d09a3fdd953b +size 216191 diff --git a/examples/desktop/screenshots/image_rgbvminvmax.png b/examples/desktop/screenshots/image_rgbvminvmax.png index eabe85d28..73707177c 100644 --- a/examples/desktop/screenshots/image_rgbvminvmax.png +++ b/examples/desktop/screenshots/image_rgbvminvmax.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7ee27d89170b30a3da7fe6d752961b30e17712d7905d8fa0686f9597debe68f9 -size 34620 +oid sha256:a6e18e9782514b3f525d8e7f8ed83699fae48fced2b633f3f1831e4b46751c44 +size 33627 diff --git a/examples/desktop/screenshots/image_simple.png b/examples/desktop/screenshots/image_simple.png index 853eb2f01..3857baf9d 100644 --- a/examples/desktop/screenshots/image_simple.png +++ b/examples/desktop/screenshots/image_simple.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e943bd3b1e00acaed274dd185f5362210e39330e0f541db9ceee489fa0a9a344 -size 189822 +oid sha256:1ab7ea5e0aa322c8b4249df30a80cbf3d7b55e0b7a0418f4bed99f81d14fdd7e +size 187665 diff --git a/examples/desktop/screenshots/image_vminvmax.png b/examples/desktop/screenshots/image_vminvmax.png index eabe85d28..73707177c 100644 --- a/examples/desktop/screenshots/image_vminvmax.png +++ b/examples/desktop/screenshots/image_vminvmax.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7ee27d89170b30a3da7fe6d752961b30e17712d7905d8fa0686f9597debe68f9 -size 34620 +oid sha256:a6e18e9782514b3f525d8e7f8ed83699fae48fced2b633f3f1831e4b46751c44 +size 33627 diff --git a/examples/desktop/screenshots/line.png b/examples/desktop/screenshots/line.png index 74cbae39a..c21a522e7 100644 --- a/examples/desktop/screenshots/line.png +++ b/examples/desktop/screenshots/line.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c8b4f4a08d1791b80d226c8c3099e37d33d8cdd7a400e4f85fb7072ee2aa3c2e -size 29121 +oid sha256:aa12348340af55e7472ceb9986a73be35b398761d057e579e199055fe6bcd9ef +size 27740 diff --git a/examples/desktop/screenshots/line_cmap.png b/examples/desktop/screenshots/line_cmap.png index 9cd93f05d..5e092c844 100644 --- a/examples/desktop/screenshots/line_cmap.png +++ b/examples/desktop/screenshots/line_cmap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d60b4ff117298f973be892773dbfc620ac855c35ca7dea42437e20bf7fcef804 -size 31050 +oid sha256:7177ca064170e815870192afd9b01dd9e23332b7cbdd962592932dacac842a76 +size 29567 diff --git a/examples/desktop/screenshots/line_collection.png b/examples/desktop/screenshots/line_collection.png index bcfe85309..cc6bdcd72 100644 --- a/examples/desktop/screenshots/line_collection.png +++ b/examples/desktop/screenshots/line_collection.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7ca99b8d74fdf7f87b0f2fc5637c59c9090b91bef868e85ddd75dbcb1264f699 -size 95146 +oid sha256:8762da25c8d01ad135288e80c91750522e32c13d824862386ad3612f63e29cfc +size 93068 diff --git a/examples/desktop/screenshots/line_collection_cmap_values.png b/examples/desktop/screenshots/line_collection_cmap_values.png index b7fcdbcae..5dbe1cfda 100644 --- a/examples/desktop/screenshots/line_collection_cmap_values.png +++ b/examples/desktop/screenshots/line_collection_cmap_values.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:68090603856eb5b961092cf2ad2d89a1e9cfd7e31f6d089b3abad101874f65d4 -size 61032 +oid sha256:ba04a638118cc6a2dff2a253fa40fae099aa2acfe347570ff4a0044403a2a5b7 +size 59102 diff --git a/examples/desktop/screenshots/line_collection_cmap_values_qualitative.png b/examples/desktop/screenshots/line_collection_cmap_values_qualitative.png index 9f89a24cc..00fde0fdd 100644 --- a/examples/desktop/screenshots/line_collection_cmap_values_qualitative.png +++ b/examples/desktop/screenshots/line_collection_cmap_values_qualitative.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9cff99e5f9faf319909571778631453c043237f5c94eece6680b028a5d7a5ac2 -size 64149 +oid sha256:a592bf90017c25abf163936c4c475b8a96ac0775e450c8d7355011fe20bbfb22 +size 62416 diff --git a/examples/desktop/screenshots/line_collection_colors.png b/examples/desktop/screenshots/line_collection_colors.png index 7bb4152fd..cf7880a6c 100644 --- a/examples/desktop/screenshots/line_collection_colors.png +++ b/examples/desktop/screenshots/line_collection_colors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a4aa17a65806300da65f4bbbfccb970d6a7207c4ca4d48b25615f627630fb484 -size 51174 +oid sha256:052a46223f73099eacf2b4672348c1110c14b22a85131b73561ac1feb8e9c796 +size 49693 diff --git a/examples/desktop/screenshots/line_collection_slicing.png b/examples/desktop/screenshots/line_collection_slicing.png index ba4170874..54d2a1098 100644 --- a/examples/desktop/screenshots/line_collection_slicing.png +++ b/examples/desktop/screenshots/line_collection_slicing.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:01090d611117fd0d2b3f9971e359871c9598a634a1829e74848b1c78a770d437 -size 131764 +oid sha256:07a02cb8a93527e913d35a0caed5dfc2feb01234d63b73ba3c3e244bbfda5e59 +size 129082 diff --git a/examples/desktop/screenshots/line_colorslice.png b/examples/desktop/screenshots/line_colorslice.png index 789265530..2bcf008a5 100644 --- a/examples/desktop/screenshots/line_colorslice.png +++ b/examples/desktop/screenshots/line_colorslice.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:25e87f566a667c98b54d4acdf115d16b486e047242b9ce8b141e5724b9d0a46a -size 33191 +oid sha256:69c4994a1259511a6480c2227a31472ab527f33f747cd44b9018f409e03ba1f1 +size 32353 diff --git a/examples/desktop/screenshots/line_dataslice.png b/examples/desktop/screenshots/line_dataslice.png index e55a6111e..395d2f1bf 100644 --- a/examples/desktop/screenshots/line_dataslice.png +++ b/examples/desktop/screenshots/line_dataslice.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e76275ea6f5719e16ff0ef3401dc33fe4b70c4c9010b3b673fca26812f33b9e8 -size 46400 +oid sha256:268a0e9a6a32e015466b7a72b8cb9675597db2b3212edaf818871a27602a751c +size 44986 diff --git a/examples/desktop/screenshots/line_present_scaling.png b/examples/desktop/screenshots/line_present_scaling.png new file mode 100644 index 000000000..ba7142106 --- /dev/null +++ b/examples/desktop/screenshots/line_present_scaling.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:06f7dd45eb495fecfcf46478c6430a658640ceb2855c4797bc184cf4134571e3 +size 20180 diff --git a/examples/desktop/screenshots/line_stack.png b/examples/desktop/screenshots/line_stack.png index 29d941fd4..edaae0d0a 100644 --- a/examples/desktop/screenshots/line_stack.png +++ b/examples/desktop/screenshots/line_stack.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:73226917c233f3fd3d7ec0b40d5a7ded904d275c871242dc0578bddf4c19d0bd -size 93687 +oid sha256:2b3ae8275e536669dfabdc8c3b715d1ca9c73f17062ab1f90f9650bd86b1c4f7 +size 91285 diff --git a/examples/desktop/screenshots/multigraphic_gridplot.png b/examples/desktop/screenshots/multigraphic_gridplot.png new file mode 100644 index 000000000..e814eadde --- /dev/null +++ b/examples/desktop/screenshots/multigraphic_gridplot.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e879a39032759006685eff1d5c2331a66b9126b13bc148734c3622bd6cdc68a7 +size 163902 diff --git a/examples/desktop/screenshots/scatter.png b/examples/desktop/screenshots/scatter.png index 94fb858e1..195c5ae64 100644 --- a/examples/desktop/screenshots/scatter.png +++ b/examples/desktop/screenshots/scatter.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4fc16a1ba74a8eca99a2fc7937f8896ca93207b99e231bc4f53845b0d2bdaed7 -size 15283 +oid sha256:b0f6c3d3b5e7216cc17c70ad3ff114092b1556fb9dcd171ae737f28d52ce51c9 +size 106634 diff --git a/examples/desktop/screenshots/scatter_cmap.png b/examples/desktop/screenshots/scatter_cmap.png index 560f1942d..55442aceb 100644 --- a/examples/desktop/screenshots/scatter_cmap.png +++ b/examples/desktop/screenshots/scatter_cmap.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9479bb3995bd145a163a2f25592a4c85c52c663d33381efee7743ffc1f16aef1 -size 32894 +oid sha256:0655f8f5f1fdeecbd5d097cf90a4776dd8125a16d0e8edb86aa37f77daba0d9b +size 107892 diff --git a/examples/desktop/screenshots/scatter_cmap_iris.png b/examples/desktop/screenshots/scatter_cmap_iris.png new file mode 100644 index 000000000..eb8802c0e --- /dev/null +++ b/examples/desktop/screenshots/scatter_cmap_iris.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:088579410d42768e68d7e7b298d2ed9e409eaff28ba5a2dd2ec8283e5994b862 +size 31599 diff --git a/examples/desktop/screenshots/scatter_colorslice.png b/examples/desktop/screenshots/scatter_colorslice.png index cede76dfd..7c43dd6cb 100644 --- a/examples/desktop/screenshots/scatter_colorslice.png +++ b/examples/desktop/screenshots/scatter_colorslice.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f7956e02d6c231bab091adb4ce9102ad4943050ccf171a0594a899a381880771 -size 14712 +oid sha256:d3319afffb554eb624d9bba5b87daf331b619ac5ec5006f13e479b613f43ca32 +size 72083 diff --git a/examples/desktop/screenshots/scatter_colorslice_iris.png b/examples/desktop/screenshots/scatter_colorslice_iris.png new file mode 100644 index 000000000..8692f53b3 --- /dev/null +++ b/examples/desktop/screenshots/scatter_colorslice_iris.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f21ab8499384298a74db3e5fbb5aa0113f714d6f77e1e3d614da3d278a2c7a78 +size 13478 diff --git a/examples/desktop/screenshots/scatter_dataslice_iris.png b/examples/desktop/screenshots/scatter_dataslice_iris.png new file mode 100644 index 000000000..c0c6aa5e7 --- /dev/null +++ b/examples/desktop/screenshots/scatter_dataslice_iris.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2032ce0b3c39f35e9dc37bc54fac016dc43aef716cfc65e6d65fd7fc977e74cf +size 14473 diff --git a/examples/desktop/screenshots/scatter_iris.png b/examples/desktop/screenshots/scatter_iris.png new file mode 100644 index 000000000..aa1d2b743 --- /dev/null +++ b/examples/desktop/screenshots/scatter_iris.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:320a02df6de51235b1912b26df4ea7633e9513df4d4034605a4e00724ceb57dc +size 14131 diff --git a/examples/desktop/screenshots/scatter_present.png b/examples/desktop/screenshots/scatter_present.png new file mode 100644 index 000000000..08bc610b3 --- /dev/null +++ b/examples/desktop/screenshots/scatter_present.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd072918f21ed0ce4ea4e1f4499ec1ff66d867cfdc0ecd6b3ed8092141cd348e +size 14195 diff --git a/examples/desktop/screenshots/scatter_size.png b/examples/desktop/screenshots/scatter_size.png index 056d2a531..2d4e559fe 100644 --- a/examples/desktop/screenshots/scatter_size.png +++ b/examples/desktop/screenshots/scatter_size.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5ccfbac94de6ba122ea420dce58e4a576b2d58d9282aaf8d64de399278df57b3 -size 38076 +oid sha256:a96a5da476b22f3ebd42ec927c3d1c1dee4dc20f261a97feaced69ed4142c645 +size 35484 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-0-reset.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-0-reset.png index 8572f6472..1369669e6 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-0-reset.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-0-reset.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ff83d6bab26b9bbccf66ed100764ffdfc7556f4cb04f0b85f50c2497ba0ab257 -size 134419 +oid sha256:7049dc9344a8d51bcfc3ba7f96a25c84db27f5072f14e8845cd2f01c3f4f5310 +size 133683 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-0.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-0.png index 8572f6472..1369669e6 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-0.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ff83d6bab26b9bbccf66ed100764ffdfc7556f4cb04f0b85f50c2497ba0ab257 -size 134419 +oid sha256:7049dc9344a8d51bcfc3ba7f96a25c84db27f5072f14e8845cd2f01c3f4f5310 +size 133683 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-279.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-279.png index e241ce5a6..5817cd299 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-279.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-279.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:337a22f11649b350f7f47d68d82be165633caeb7f8cef581e50f981d6ec0c52c -size 169615 +oid sha256:1ca687c654679ee9d47a053196fb65d92105ed6cce76f0d2d1775582053e7b07 +size 168750 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-max-33.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-max-33.png index b827fc536..2f2e310d0 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-max-33.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-max-33.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:22ff3ed815fcbe8bc95c321c806a4b42536e7014209cd43ac597a5ccefd8b9c6 -size 149261 +oid sha256:dd51516d18f550f62b9f2c989cfae82d267eb6de1d8757cf44949bb41c3b13c2 +size 148408 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-13.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-13.png index d37f44a3a..39a4f1274 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-13.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-13.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:11143f73a297d0b59c92db1b115ceac1bc1304135a9925302e616a4fd3669b25 -size 125012 +oid sha256:9613c10e63261ddbcf3274a9804bdf3a1be0734c1190720663b01f8b2ae48389 +size 124532 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-33.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-33.png index 46d3fa9b3..b9feacb82 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-33.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-mean-33.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7438018c3b55d423f57c42a9d03c1af6d5de168a2dfa5df9d535ef2ae1f1c8e9 -size 113981 +oid sha256:8fa86b26f11bd9655c60e43ddd88ada618cea1ba06b3dcddcb408569c09a7750 +size 113897 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-reset.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-reset.png index 6146a7985..ae280a970 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-reset.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-50-window-reset.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9b57a1e6640de9471540fa4d86faadb706d6de8cc1de6a29fb65d709b91eef1e -size 146429 +oid sha256:aca573ba6dcda8ad8f018a96790b1b1aa5da25fe9584a57c2c946e1cf2df9e5c +size 145275 diff --git a/examples/notebooks/screenshots/nb-image-widget-movie-single-50.png b/examples/notebooks/screenshots/nb-image-widget-movie-single-50.png index 6146a7985..ae280a970 100644 --- a/examples/notebooks/screenshots/nb-image-widget-movie-single-50.png +++ b/examples/notebooks/screenshots/nb-image-widget-movie-single-50.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9b57a1e6640de9471540fa4d86faadb706d6de8cc1de6a29fb65d709b91eef1e -size 146429 +oid sha256:aca573ba6dcda8ad8f018a96790b1b1aa5da25fe9584a57c2c946e1cf2df9e5c +size 145275 diff --git a/examples/notebooks/screenshots/nb-lines-3d.png b/examples/notebooks/screenshots/nb-lines-3d.png index a3b75de58..6c19c965c 100644 --- a/examples/notebooks/screenshots/nb-lines-3d.png +++ b/examples/notebooks/screenshots/nb-lines-3d.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:677f544d93cf7a733003c38666f555f0b598d41b92681dd2f09e6c11faa4aed0 -size 14186 +oid sha256:c6ab8d74c980a02505d5d626d170b60847ce2b733ea5b47278a1f48228011a38 +size 14181 diff --git a/examples/notebooks/screenshots/nb-lines-cmap-jet-values-cosine.png b/examples/notebooks/screenshots/nb-lines-cmap-jet-values-cosine.png index 0d9ff5729..f75d83ba4 100644 --- a/examples/notebooks/screenshots/nb-lines-cmap-jet-values-cosine.png +++ b/examples/notebooks/screenshots/nb-lines-cmap-jet-values-cosine.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0d981d57d7905879ab68af95da84d2cf530a9a40dc4d0ffb138119a11f4966be -size 11808 +oid sha256:d2b87297587b5f76062132370fdf7e8318cbde68d38d12a0179548f9790c2af8 +size 11765 diff --git a/examples/notebooks/screenshots/nb-lines-cmap-jet-values.png b/examples/notebooks/screenshots/nb-lines-cmap-jet-values.png index dbcbf1e7f..a8229cfc8 100644 --- a/examples/notebooks/screenshots/nb-lines-cmap-jet-values.png +++ b/examples/notebooks/screenshots/nb-lines-cmap-jet-values.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:706bffa485dd7994a70602ef2076aee79e1206dd508fbac903549fce526087b6 -size 13095 +oid sha256:99f6a7a9a1399aaf8d1070812c41f03f80ba41812a1acf9d4bdd17641bc589f4 +size 13038 diff --git a/examples/notebooks/screenshots/nb-lines-cmap-jet.png b/examples/notebooks/screenshots/nb-lines-cmap-jet.png index 6a3ae0c1c..ccc897f66 100644 --- a/examples/notebooks/screenshots/nb-lines-cmap-jet.png +++ b/examples/notebooks/screenshots/nb-lines-cmap-jet.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cfd3f55e1671ac1fa45a8eb26aeb425ccb8d1ac033f5766f4002fee4380b2a77 -size 11174 +oid sha256:cac3d7cb23d7ec207cdf7fd7032037c7749e30563754d6c2cac50d67a7731a2d +size 11086 diff --git a/examples/notebooks/screenshots/nb-lines-cmap-tab-10.png b/examples/notebooks/screenshots/nb-lines-cmap-tab-10.png index 9bb368e0e..8ddc44ead 100644 --- a/examples/notebooks/screenshots/nb-lines-cmap-tab-10.png +++ b/examples/notebooks/screenshots/nb-lines-cmap-tab-10.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:338dbcdf1a87266eee33367bfa08bcaec7eac42ef2dd928bbc699b3a0412ebaf -size 9889 +oid sha256:d38a2c27e5b598883c40b44e45b347f029a7369b638bc4111ef2d69978245378 +size 9943 diff --git a/examples/notebooks/screenshots/nb-lines-cmap-viridis-values.png b/examples/notebooks/screenshots/nb-lines-cmap-viridis-values.png index 23137bdf3..6bf270874 100644 --- a/examples/notebooks/screenshots/nb-lines-cmap-viridis-values.png +++ b/examples/notebooks/screenshots/nb-lines-cmap-viridis-values.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e36a7a74ac39dac5ac96a4e7c8e56990794ab1cda1b8ee5276087e9814dd1696 -size 10100 +oid sha256:d0ead67733470d6afcb2228645ee1a056acd525d369d74c16b1054783d6ab4f5 +size 10155 diff --git a/examples/notebooks/screenshots/nb-lines-cmap-viridis.png b/examples/notebooks/screenshots/nb-lines-cmap-viridis.png index 2fcd4749c..4f99e5fb5 100644 --- a/examples/notebooks/screenshots/nb-lines-cmap-viridis.png +++ b/examples/notebooks/screenshots/nb-lines-cmap-viridis.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b12ee5e31f64415b57536c59587b91c7a3a7c74e95be3459d8036a43d073d7db -size 13821 +oid sha256:15f4decaa6ba08f09a988771c5dc433629cb9e3bccfa08f820268366a3ff06a6 +size 13761 diff --git a/examples/notebooks/screenshots/nb-lines-cmap-white.png b/examples/notebooks/screenshots/nb-lines-cmap-white.png index 397b5fc94..85e43aa5e 100644 --- a/examples/notebooks/screenshots/nb-lines-cmap-white.png +++ b/examples/notebooks/screenshots/nb-lines-cmap-white.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6239f23d3b5c1745879f5706352abb905d5638522b171776bff051e511426c2f -size 8359 +oid sha256:8a623f31d28533cc6052143856d0ef2e827b42891397fa4ac20d358f44d751d7 +size 8332 diff --git a/examples/notebooks/screenshots/nb-lines-colors.png b/examples/notebooks/screenshots/nb-lines-colors.png index 149321e52..ab50dfaaf 100644 --- a/examples/notebooks/screenshots/nb-lines-colors.png +++ b/examples/notebooks/screenshots/nb-lines-colors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9a5e99c5a872d9bbf8dd909498459ddee7f22f08d3fe3cd68b3ea57c105ab51b -size 27634 +oid sha256:0cbcafef567bff33762d64bcf6f83c7a1982015ea21d508b1e6564cb0d8435d2 +size 27420 diff --git a/examples/notebooks/screenshots/nb-lines-data.png b/examples/notebooks/screenshots/nb-lines-data.png index 9ed38b1f5..88f1001ad 100644 --- a/examples/notebooks/screenshots/nb-lines-data.png +++ b/examples/notebooks/screenshots/nb-lines-data.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cc0d3d6819ce0d9f5d531276bbde0397ef35e3084ac1f9b3575f0209eea07456 -size 39512 +oid sha256:f62dc16cd1ea212cf29974a64e6ad2dd3d7ae10d7b3eef573c25316bbe89b097 +size 38740 diff --git a/examples/notebooks/screenshots/nb-lines-underlay.png b/examples/notebooks/screenshots/nb-lines-underlay.png index e7f6aeb0c..f9650e253 100644 --- a/examples/notebooks/screenshots/nb-lines-underlay.png +++ b/examples/notebooks/screenshots/nb-lines-underlay.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8ed174c362c7e7c491eba02b32102f59423af41537577c694fdcd54d69c065b3 -size 50422 +oid sha256:ec7881cc0084b0ea2182f8d4f6f23388a4d48b88dbbf9c06b9dc2fa8125989b7 +size 49553 diff --git a/examples/notebooks/screenshots/nb-lines.png b/examples/notebooks/screenshots/nb-lines.png index 603f4a8fc..7df6ea14f 100644 --- a/examples/notebooks/screenshots/nb-lines.png +++ b/examples/notebooks/screenshots/nb-lines.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:eeef2c47e7dde62038307fa7929a306801bf8b708fbcf1062ed9c751727bfb2b -size 24300 +oid sha256:b925337438aa24f0179a8b5c1688e154679fa002402a16746b6bb3cd6684af1e +size 24246 diff --git a/examples/tests/test_examples.py b/examples/tests/test_examples.py index b8369e368..c08df9005 100644 --- a/examples/tests/test_examples.py +++ b/examples/tests/test_examples.py @@ -69,7 +69,7 @@ def test_example_screenshots(module, force_offscreen): example = importlib.import_module(module_name) # render a frame - img = np.asarray(example.fig.renderer.target.draw()) + img = np.asarray(example.figure.renderer.target.draw()) # check if _something_ was rendered assert img is not None and img.size > 0 diff --git a/examples/tests/testutils.py b/examples/tests/testutils.py index f62ae7602..22747ce08 100644 --- a/examples/tests/testutils.py +++ b/examples/tests/testutils.py @@ -22,7 +22,8 @@ "scatter/*.py", "line/*.py", "line_collection/*.py", - "gridplot/*.py" + "gridplot/*.py", + "misc/*.py" ] diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index 2c157db8f..17bb28095 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -475,11 +475,6 @@ def show( _maintain_aspect = maintain_aspect subplot.auto_scale(maintain_aspect=_maintain_aspect, zoom=0.95) - # used for generating images in docs using nbsphinx - if "NB_SNAPSHOT" in os.environ.keys(): - if os.environ["NB_SNAPSHOT"] == "1": - return self.canvas.snapshot() - # return the appropriate OutputContext based on the current canvas if self.canvas.__class__.__name__ == "JupyterWgpuCanvas": from .output.jupyter_output import ( diff --git a/setup.py b/setup.py index 3ba77201d..503af8f99 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ extras_require = { "docs": [ "sphinx", + "sphinx-gallery", "furo", "glfw", "jupyter-rfb>=0.4.1", # required so ImageWidget docs show up @@ -21,6 +22,9 @@ "pandoc", "jupyterlab", "sidecar", + "imageio", + "matplotlib", + "scikit-learn" ], "notebook": [ "jupyterlab",