-
Notifications
You must be signed in to change notification settings - Fork 50
sphinx gallery #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sphinx gallery #509
Changes from all commits
22e1c85
71c1eaf
c8eb15d
e97f37b
5e0d08c
1acbbfb
372e466
b4dbc94
0fc05dd
2856365
dacc382
985eb2e
79b6e7f
9c447de
c92e5b7
676a481
09acb24
f749ef3
59ec3fb
d0852f4
7efad6b
16c712c
98d5280
ff3f429
1fba2c4
3ff1982
26d85e4
ea298dc
950d4b4
64aaca7
27c90aa
ee2d8f1
0e199ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Examples that use fastplotlib | ||
============================= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GridPlot Examples | ||
================= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
clewis7 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make a section, perhaps in the guide, on using fpl interactively in jupyter lab and ipython, the wgpu docs might provide some inspiration: https://wgpu-py.readthedocs.io/en/stable/gui.html#using-wgpu-interactively but basically, there is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if __name__ == "__main__": | ||
print(__doc__) | ||
fpl.run() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Heatmap Examples | ||
================ |
Uh oh!
There was an error while loading. Please reload this page.