Content-Length: 1294517 | pFad | http://github.com/fastplotlib/fastplotlib/commit/bb0bb273ce0be1cdc1b56a1d0702b39d7cdbccc7

5F sphinx gallery (#509) · fastplotlib/fastplotlib@bb0bb27 · GitHub
Skip to content

Commit bb0bb27

Browse files
clewis7kushalkolar
andauthored
sphinx gallery (#509)
* start sphinx gallery * relevant file changes * progress * edit setup.py to include missing dependencies * attempt to fix rtd * remove large heatmap example that breaks rtd * fix linter, attempt to fix quickstart bug * fix gridplot examples and gallery structure * remove nbsphinx * remove nbsphinx and quickstart.ipynb from docs * remove init files from examples * update examples and conf.py * add animation examples, edit conf.py, fix scatter examples * add sklearn to docs, example needs it * Update setup.py * Update setup.py * remove from gallery, kills readthedocs runner * update canvas size so thumbnails render better * change scatter examples, remove sklearn from docs dependencies * add iris scatter examples, exclude from screenshot tests * add more animation examples, add to tests * add simple multigraphic gridplot example * add simple event, fix multigraphic gridplot * Update line3d_animation.py * add simple event example * minor changes * replace screenshots and fix small bug * fix scatter examples for CI build * fix screenshots * add sklearn as docs dependency, include iris scatter examples in gallery * Update examples/desktop/misc/simple_event.py Co-authored-by: Kushal Kolar <kushalkolar@gmail.com> * update screenshots --------- Co-authored-by: Kushal Kolar <kushalkolar@gmail.com>
1 parent e08d197 commit bb0bb27

File tree

117 files changed

+1330
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1330
-355
lines changed

docs/source/conf.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,24 @@
22
#
33
# For the full list of built-in configuration values, see the documentation:
44
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
import os
7+
8+
# need to force offscreen rendering before importing fpl
9+
# otherwise fpl tries to select glfw canvas
10+
os.environ["WGPU_FORCE_OFFSCREEN"] = "1"
11+
512
import fastplotlib
13+
from pygfx.utils.gallery_scraper import find_examples_for_gallery
14+
from pathlib import Path
15+
import sys
16+
from sphinx_gallery.sorting import ExplicitOrder
17+
import imageio.v3 as iio
18+
19+
ROOT_DIR = Path(__file__).parents[1].parents[0] # repo root
20+
EXAMPLES_DIR = Path.joinpath(ROOT_DIR, "examples", "desktop")
21+
22+
sys.path.insert(0, str(ROOT_DIR))
623

724
# -- Project information -----------------------------------------------------
825
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
@@ -23,8 +40,40 @@
2340
"sphinx.ext.viewcode",
2441
"sphinx_copybutton",
2542
"sphinx_design",
43+
"sphinx_gallery.gen_gallery"
2644
]
2745

46+
sphinx_gallery_conf = {
47+
"gallery_dirs": "_gallery",
48+
"backreferences_dir": "_gallery/backreferences",
49+
"doc_module": ("fastplotlib",),
50+
"image_scrapers": ("pygfx",),
51+
"remove_config_comments": True,
52+
"subsection_order": ExplicitOrder(
53+
[
54+
"../../examples/desktop/image",
55+
"../../examples/desktop/gridplot",
56+
"../../examples/desktop/line",
57+
"../../examples/desktop/line_collection",
58+
"../../examples/desktop/scatter",
59+
"../../examples/desktop/heatmap",
60+
"../../examples/desktop/misc"
61+
]
62+
),
63+
"ignore_pattern": r'__init__\.py',
64+
"nested_sections": False,
65+
"thumbnail_size": (250, 250)
66+
}
67+
68+
extra_conf = find_examples_for_gallery(EXAMPLES_DIR)
69+
sphinx_gallery_conf.update(extra_conf)
70+
71+
# download imageio examples for the gallery
72+
iio.imread("imageio:clock.png")
73+
iio.imread("imageio:astronaut.png")
74+
iio.imread("imageio:coffee.png")
75+
iio.imread("imageio:hubble_deep_field.png")
76+
2877
autosummary_generate = True
2978

3079
templates_path = ["_templates"]
@@ -56,7 +105,7 @@
56105
}
57106

58107
html_theme_options = {
59-
"source_repository": "https://github.com/kushalkolar/fastplotlib",
108+
"source_repository": "https://github.com/fastplotlib/fastplotlib",
60109
"source_branch": "main",
61110
"source_directory": "docs/",
62111
}

docs/source/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Welcome to fastplotlib's documentation!
2020
Utils <api/utils>
2121
GPU <api/gpu>
2222

23+
.. toctree::
24+
:caption: Gallery
25+
:maxdepth: 1
26+
27+
Gallery <_gallery/index>
28+
2329
Summary
2430
=======
2531

examples/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Examples that use fastplotlib
2+
=============================
File renamed without changes.

examples/desktop/gridplot/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GridPlot Examples
2+
=================

examples/desktop/gridplot/gridplot.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
"""
22
GridPlot Simple
3-
============
3+
===============
4+
45
Example showing simple 2x2 GridPlot with Standard images from imageio.
56
"""
67

78
# test_example = true
9+
# sphinx_gallery_pygfx_docs = 'screenshot'
810

911
import fastplotlib as fpl
1012
import imageio.v3 as iio
1113

12-
13-
fig = fpl.Figure(shape=(2, 2))
14+
figure = fpl.Figure(shape=(2, 2))
1415

1516
im = iio.imread("imageio:clock.png")
1617
im2 = iio.imread("imageio:astronaut.png")
1718
im3 = iio.imread("imageio:coffee.png")
1819
im4 = iio.imread("imageio:hubble_deep_field.png")
1920

20-
fig[0, 0].add_image(data=im)
21-
fig[0, 1].add_image(data=im2)
22-
fig[1, 0].add_image(data=im3)
23-
fig[1, 1].add_image(data=im4)
21+
figure[0, 0].add_image(data=im)
22+
figure[0, 1].add_image(data=im2)
23+
figure[1, 0].add_image(data=im3)
24+
figure[1, 1].add_image(data=im4)
2425

25-
fig.show()
26+
figure.show()
2627

27-
fig.canvas.set_logical_size(800, 800)
28+
figure.canvas.set_logical_size(700, 560)
2829

29-
for subplot in fig:
30+
for subplot in figure:
3031
subplot.auto_scale()
3132

33+
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
34+
# please see our docs for using fastplotlib interactively in ipython and jupyter
3235
if __name__ == "__main__":
3336
print(__doc__)
3437
fpl.run()
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
"""
2-
GridPlot Simple
3-
============
2+
GridPlot Non-Square Example
3+
===========================
4+
45
Example showing simple 2x2 GridPlot with Standard images from imageio.
56
"""
67

78
# test_example = true
9+
# sphinx_gallery_pygfx_docs = 'screenshot'
810

911
import fastplotlib as fpl
1012
import imageio.v3 as iio
1113

12-
13-
fig = fpl.Figure(shape=(2, 2), controller_ids="sync")
14+
figure = fpl.Figure(shape=(2, 2), controller_ids="sync")
1415

1516
im = iio.imread("imageio:clock.png")
1617
im2 = iio.imread("imageio:astronaut.png")
1718
im3 = iio.imread("imageio:coffee.png")
1819

19-
fig[0, 0].add_image(data=im)
20-
fig[0, 1].add_image(data=im2)
21-
fig[1, 0].add_image(data=im3)
20+
figure[0, 0].add_image(data=im)
21+
figure[0, 1].add_image(data=im2)
22+
figure[1, 0].add_image(data=im3)
2223

23-
fig.show()
24+
figure.show()
2425

25-
fig.canvas.set_logical_size(800, 800)
26+
figure.canvas.set_logical_size(700, 560)
2627

27-
for subplot in fig:
28+
for subplot in figure:
2829
subplot.auto_scale()
2930

31+
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
32+
# please see our docs for using fastplotlib interactively in ipython and jupyter
3033
if __name__ == "__main__":
3134
print(__doc__)
3235
fpl.run()
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""
2+
Multi-Graphic GridPlot
3+
======================
4+
5+
Example showing a Figure with multiple subplots and multiple graphic types.
6+
"""
7+
8+
# test_example = true
9+
# sphinx_gallery_pygfx_docs = 'screenshot'
10+
11+
import fastplotlib as fpl
12+
import numpy as np
13+
import imageio.v3 as iio
14+
from itertools import product
15+
16+
# define figure
17+
figure = fpl.Figure(shape=(2, 2), names=[["image-overlay", "circles"], ["line-stack", "scatter"]])
18+
19+
img = iio.imread("imageio:coffee.png")
20+
21+
# add image to subplot
22+
figure["image-overlay"].add_image(data=img)
23+
24+
# generate overlay
25+
26+
# empty array for overlay, shape is [nrows, ncols, RGBA]
27+
overlay = np.zeros(shape=(*img.shape[:2], 4), dtype=np.float32)
28+
29+
# set the blue values of some pixels with an alpha > 1
30+
overlay[img[:, :, -1] > 200] = np.array([0.0, 0.0, 1.0, 0.6]).astype(np.float32)
31+
32+
# add overlay to image
33+
figure["image-overlay"].add_image(data=overlay)
34+
35+
# generate some circles
36+
def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
37+
theta = np.linspace(0, 2 * np.pi, n_points)
38+
xs = radius * np.sin(theta)
39+
ys = radius * np.cos(theta)
40+
41+
return np.column_stack([xs, ys]) + center
42+
43+
44+
spatial_dims = (50, 50)
45+
46+
# this makes 16 circles, so we can create 16 cmap values, so it will use these values to set the
47+
# color of the line based by using the cmap as a LUT with the corresponding cmap_transform
48+
circles = list()
49+
for center in product(range(0, spatial_dims[0], 15), range(0, spatial_dims[1], 15)):
50+
circles.append(make_circle(center, 5, n_points=75))
51+
52+
# things like class labels, cluster labels, etc.
53+
cmap_transform = [
54+
0, 1, 1, 2,
55+
0, 0, 1, 1,
56+
2, 2, 8, 3,
57+
1, 9, 1, 5
58+
]
59+
60+
# add an image to overlay the circles on
61+
img2 = np.ones((60, 60))
62+
63+
figure["circles"].add_image(data=img2)
64+
65+
# add the circles to the figure
66+
figure["circles"].add_line_collection(
67+
circles,
68+
cmap="tab10",
69+
cmap_transform=cmap_transform,
70+
thickness=3,
71+
alpha=0.5,
72+
name="circles-graphic"
73+
)
74+
75+
# move the circles graphic so that it is centered over the image
76+
figure["circles"]["circles-graphic"].offset = np.array([7, 7, 2])
77+
78+
# generate some sine data
79+
# linspace, create 100 evenly spaced x values from -10 to 10
80+
xs = np.linspace(-10, 10, 100)
81+
# sine wave
82+
ys = np.sin(xs)
83+
sine = np.dstack([xs, ys])[0]
84+
85+
# make 10 identical waves
86+
sine_waves = 10 * [sine]
87+
88+
# add the line stack to the figure
89+
figure["line-stack"].add_line_stack(data=sine_waves, cmap="Wistia", separation=1)
90+
91+
figure["line-stack"].auto_scale(maintain_aspect=True)
92+
93+
# generate some scatter data
94+
# create a gaussian cloud of 500 points
95+
n_points = 500
96+
97+
mean = [0, 0] # mean of the Gaussian distribution
98+
covariance = [[1, 0], [0, 1]] # covariance matrix
99+
100+
gaussian_cloud = np.random.multivariate_normal(mean, covariance, n_points)
101+
gaussian_cloud2 = np.random.multivariate_normal(mean, covariance, n_points)
102+
103+
# add the scatter graphics to the figure
104+
figure["scatter"].add_scatter(data=gaussian_cloud, sizes=1, cmap="jet")
105+
figure["scatter"].add_scatter(data=gaussian_cloud2, colors="r", sizes=1)
106+
107+
figure.show()
108+
109+
figure.canvas.set_logical_size(700, 560)
110+
111+
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
112+
# please see our docs for using fastplotlib interactively in ipython and jupyter
113+
if __name__ == "__main__":
114+
print(__doc__)
115+
fpl.run()
116+

examples/desktop/heatmap/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Heatmap Examples
2+
================

examples/desktop/heatmap/__init__.py

Whitespace-only changes.

examples/desktop/heatmap/heatmap.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"""
66

77
# test_example = true
8+
# sphinx_gallery_pygfx_docs = 'screenshot'
89

910
import fastplotlib as fpl
1011
import numpy as np
1112

12-
13-
fig = fpl.Figure()
13+
figure = fpl.Figure()
1414

1515
xs = np.linspace(0, 1_000, 10_000, dtype=np.float32)
1616

@@ -19,14 +19,16 @@
1919
data = np.vstack([sine * i for i in range(20_000)])
2020

2121
# plot the image data
22-
img = fig[0, 0].add_image(data=data, name="heatmap")
22+
img = figure[0, 0].add_image(data=data, name="heatmap")
2323

24-
fig.show()
24+
figure.show()
2525

26-
fig.canvas.set_logical_size(1500, 1500)
26+
figure.canvas.set_logical_size(700, 560)
2727

28-
fig[0, 0].auto_scale()
28+
figure[0, 0].auto_scale()
2929

30+
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
31+
# please see our docs for using fastplotlib interactively in ipython and jupyter
3032
if __name__ == "__main__":
3133
print(__doc__)
3234
fpl.run()

examples/desktop/heatmap/heatmap_cmap.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
Change the cmap of a heatmap
55
"""
66

7+
78
# test_example = false
9+
# sphinx_gallery_pygfx_docs = 'hidden'
810

911
import fastplotlib as fpl
1012
import numpy as np
1113

12-
13-
fig = fpl.Figure()
14+
figure = fpl.Figure()
1415

1516
xs = np.linspace(0, 1_000, 10_000, dtype=np.float32)
1617

@@ -19,16 +20,18 @@
1920
data = np.vstack([sine * i for i in range(20_000)])
2021

2122
# plot the image data
22-
img = fig[0, 0].add_image(data=data, name="heatmap")
23+
img = figure[0, 0].add_image(data=data, name="heatmap")
2324

24-
fig.show()
25+
figure.show()
2526

26-
fig.canvas.set_logical_size(1500, 1500)
27+
figure.canvas.set_logical_size(700, 560)
2728

28-
fig[0, 0].auto_scale()
29+
figure[0, 0].auto_scale()
2930

3031
img.cmap = "viridis"
3132

33+
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
34+
# please see our docs for using fastplotlib interactively in ipython and jupyter
3235
if __name__ == "__main__":
3336
print(__doc__)
3437
fpl.run()

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/fastplotlib/fastplotlib/commit/bb0bb273ce0be1cdc1b56a1d0702b39d7cdbccc7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy