Skip to content
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

Merged
merged 33 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
22e1c85
start sphinx gallery
clewis7 May 29, 2024
71c1eaf
relevant file changes
clewis7 May 29, 2024
c8eb15d
progress
clewis7 May 30, 2024
e97f37b
edit setup.py to include missing dependencies
clewis7 May 30, 2024
5e0d08c
attempt to fix rtd
clewis7 May 30, 2024
1acbbfb
remove large heatmap example that breaks rtd
clewis7 May 30, 2024
372e466
fix linter, attempt to fix quickstart bug
clewis7 May 30, 2024
b4dbc94
fix gridplot examples and gallery structure
clewis7 Jun 3, 2024
0fc05dd
remove nbsphinx
clewis7 Jun 4, 2024
2856365
remove nbsphinx and quickstart.ipynb from docs
clewis7 Jun 4, 2024
dacc382
remove init files from examples
clewis7 Jun 4, 2024
985eb2e
update examples and conf.py
clewis7 Jun 5, 2024
79b6e7f
add animation examples, edit conf.py, fix scatter examples
clewis7 Jun 5, 2024
9c447de
add sklearn to docs, example needs it
clewis7 Jun 5, 2024
c92e5b7
Update setup.py
clewis7 Jun 5, 2024
676a481
Update setup.py
clewis7 Jun 5, 2024
09acb24
remove from gallery, kills readthedocs runner
clewis7 Jun 5, 2024
f749ef3
update canvas size so thumbnails render better
clewis7 Jun 5, 2024
59ec3fb
change scatter examples, remove sklearn from docs dependencies
clewis7 Jun 5, 2024
d0852f4
add iris scatter examples, exclude from screenshot tests
clewis7 Jun 5, 2024
7efad6b
add more animation examples, add to tests
clewis7 Jun 5, 2024
16c712c
add simple multigraphic gridplot example
clewis7 Jun 5, 2024
98d5280
add simple event, fix multigraphic gridplot
clewis7 Jun 6, 2024
ff3f429
Update line3d_animation.py
clewis7 Jun 6, 2024
1fba2c4
add simple event example
clewis7 Jun 6, 2024
3ff1982
resolve merge conflicts, change fig to figure for gallery
clewis7 Jun 17, 2024
26d85e4
minor changes
clewis7 Jun 18, 2024
ea298dc
replace screenshots and fix small bug
clewis7 Jun 18, 2024
950d4b4
fix scatter examples for CI build
clewis7 Jun 18, 2024
64aaca7
fix screenshots
clewis7 Jun 18, 2024
27c90aa
add sklearn as docs dependency, include iris scatter examples in gallery
clewis7 Jun 18, 2024
ee2d8f1
Update examples/desktop/misc/simple_event.py
clewis7 Jun 18, 2024
0e199ea
update screenshots
clewis7 Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/desktop/line_collection/line_stack_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

# test_example = false
# sphinx_gallery_pygfx_docs = 'hidden'
# sphinx_gallery_pygfx_docs = 'animate'

import numpy as np
import fastplotlib as fpl
Expand Down Expand Up @@ -97,8 +97,10 @@ def animate_colors(subplot):

figure[0, 0].camera.set_state(camera_state)

figure.canvas.set_logical_size(500, 500)
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()
55 changes: 21 additions & 34 deletions examples/desktop/misc/simple_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,43 @@
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import numpy as np
import imageio.v3 as iio

# generate some date
# 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.column_stack([xs, ys])

# cosine wave
ys = np.cos(xs) + 5
cosine = np.column_stack([xs, ys])

# sinc function
a = 0.5
ys = np.sinc(xs) * 3 + 8
sinc = np.column_stack([xs, ys])
data = iio.imread("imageio:camera.png")

# Create a figure
figure = fpl.Figure()

# we will add all the lines to the same subplot
subplot = figure[0, 0]

# plot sine wave, use a single color
sine_graphic = subplot.add_line(data=sine, thickness=5, colors="magenta")

# you can also use colormaps for lines!
cosine_graphic = subplot.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 = subplot.add_line(data=sinc, thickness=5, colors=colors)
image_graphic = figure[0,0].add_image(data=data)

# show the plot
figure.show()

subplot.auto_scale(maintain_aspect=True)


# define callback function to print the event data
def callback_func(event_data):
print(event_data)
print(event_data.info)


# Will print event data when the color changes
cosine_graphic.colors.add_event_handler(callback_func)
image_graphic.add_event_handler(callback_func, "cmap")

image_graphic.cmap = "viridis"


# adding a click event
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
@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)

# more complex indexing of colors
# from point 15 - 30, set every 3rd point as "cyan"
cosine_graphic.colors[15:50:3] = "cyan"

figure.canvas.set_logical_size(700, 560)

Expand Down
2 changes: 1 addition & 1 deletion examples/desktop/scatter/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Example showing scatter plot.
"""

# test_example = true
# test_example = false
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
Expand Down
2 changes: 1 addition & 1 deletion examples/desktop/scatter/scatter_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Example showing cmap change for scatter plot.
"""

# test_example = true
# test_example = false
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
Expand Down
44 changes: 44 additions & 0 deletions examples/desktop/scatter/scatter_cmap_iris.py
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Iris Scatter Colormap
=====================

Example showing cmap change for scatter plot.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'
clewis7 marked this conversation as resolved.
Show resolved Hide resolved

import fastplotlib as fpl
import numpy as np
from pathlib import Path
from sklearn.cluster import AgglomerativeClustering

clewis7 marked this conversation as resolved.
Show resolved Hide resolved

figure = fpl.Figure()

data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy")
data = np.load(data_path)
clewis7 marked this conversation as resolved.
Show resolved Hide resolved

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(800, 800)

figure[0, 0].auto_scale()

scatter_graphic.cmap = "tab10"


if __name__ == "__main__":
print(__doc__)
fpl.run()
2 changes: 1 addition & 1 deletion examples/desktop/scatter/scatter_colorslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Example showing color slice for scatter plot.
"""

# test_example = true
# test_example = false
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
Expand Down
44 changes: 44 additions & 0 deletions examples/desktop/scatter/scatter_colorslice_iris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Iris Scatter Plot Color Slicing
===============================

Example showing color slice for scatter plot.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import numpy as np
from pathlib import Path


figure = fpl.Figure()

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 # use colors from the list of strings
)

figure.show()

figure.canvas.set_logical_size(800, 800)

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()
2 changes: 1 addition & 1 deletion examples/desktop/scatter/scatter_dataslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Example showing data slice for scatter plot.
"""

# test_example = true
# test_example = false
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
Expand Down
42 changes: 42 additions & 0 deletions examples/desktop/scatter/scatter_dataslice_iris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Iris Scatter Plot Data Slicing
==============================

Example showing data slice for scatter plot.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import numpy as np
from pathlib import Path


figure = fpl.Figure()

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(800, 800)

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()
6 changes: 3 additions & 3 deletions examples/desktop/scatter/scatter_iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Example showing scatter plot using sklearn iris dataset.
"""

# test_example = false
# sphinx_gallery_pygfx_docs = 'screenshot'
# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import numpy as np
Expand All @@ -17,7 +17,7 @@

current_file = Path(sys.argv[0]).resolve()

data_path = Path(current_file.parent.parent.joinpath("data", "iris.npy"))
data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy")
data = np.load(data_path)

n_points = 50
Expand Down
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/gridplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/gridplot_non_square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/heatmap.png
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/image_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/image_rgb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/image_rgbvminvmax.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/image_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/image_vminvmax.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/line_cmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/line_collection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/line_collection_colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/desktop/screenshots/line_collection_slicing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/line_colorslice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/line_dataslice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/line_stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/desktop/screenshots/multigraphic_gridplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading