Skip to content

Update examples #261

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

Merged
merged 8 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ jobs:
PYGFX_EXPECT_LAVAPIPE: true
run: |
pytest -v examples
pytest --nbmake notebooks/
pytest --nbmake examples/notebooks/
- uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: screenshot-diffs
path: examples/diffs
path: examples/desktop/diffs
2 changes: 1 addition & 1 deletion .github/workflows/screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
if: always()
with:
name: screenshots
path: examples/screenshots/
path: examples/desktop/screenshots/
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,37 @@ pip install -e ".[notebook,docs,tests]"
>
> `fastplotlib` and `pygfx` are fast evolving, you may require the latest `pygfx` and `fastplotlib` from github to use the examples in the master branch.

Clone or download the repo to try the examples
First clone or download the repo to try the examples

```bash
# clone the repo
git clone https://github.com/kushalkolar/fastplotlib.git
```

### Desktop examples using `glfw` or `Qt`

# IMPORTANT: if you are using a specific version from pip, checkout that version to get the examples which work for that version
# example:
# git checkout git checkout v0.1.0.a9 # replace "v0.1.0.a9" with the version you have
```bash
# most dirs within examples contain example code
cd examples/desktop

# cd into notebooks and launch jupyter lab
cd fastplotlib/notebooks
# simplest example
python image/image_simple.py
```

### Notebook examples

```bash
cd examples/notebooks
jupyter lab
```

**Start out with `simple.ipynb`.**

### Simple image plot
```python
from fastplotlib import Plot
import fastplotlib as fpl
import numpy as np

plot = Plot()
plot = fpl.Plot()

data = np.random.rand(512, 512)
plot.add_image(data=data)
Expand All @@ -110,10 +118,10 @@ plot.show()

### Fast animations
```python
from fastplotlib import Plot
import fastplotlib as fpl
import numpy as np

plot = Plot()
plot = fpl.Plot()

data = np.random.rand(512, 512)
image = plot.image(data=data)
Expand Down
6 changes: 0 additions & 6 deletions examples/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

# test_example = true

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

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = GridPlot(shape=(2,2), canvas=canvas, renderer=renderer)
plot = fpl.GridPlot(shape=(2, 2))
# to force a specific framework such as glfw:
# plot = fpl.GridPlot(canvas="glfw")

im = iio.imread("imageio:clock.png")
im2 = iio.imread("imageio:astronaut.png")
Expand All @@ -35,7 +31,6 @@
for subplot in plot:
subplot.auto_scale()

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
fpl.run()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
"""
# test_example = true

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

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

im = iio.imread("imageio:camera.png")

Expand All @@ -30,7 +26,6 @@

image_graphic.cmap = "viridis"

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
"""
# test_example = true

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

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

im = iio.imread("imageio:astronaut.png")

Expand All @@ -28,7 +24,7 @@

plot.auto_scale()

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
"""
# test_example = true

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

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

im = iio.imread("imageio:astronaut.png")

Expand All @@ -31,7 +27,7 @@
image_graphic.cmap.vmin = 0.5
image_graphic.cmap.vmax = 0.75

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

# test_example = true

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

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

data = iio.imread("imageio:camera.png")

Expand All @@ -29,7 +25,6 @@

plot.auto_scale()

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
"""
# test_example = true

from fastplotlib import Plot
import numpy as np
from pathlib import Path
import fastplotlib as fpl
import imageio.v3 as iio

from wgpu.gui.offscreen import WgpuCanvas
from pygfx import WgpuRenderer

canvas = WgpuCanvas()
renderer = WgpuRenderer(canvas)

plot = Plot(canvas=canvas, renderer=renderer)
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

data = iio.imread("imageio:astronaut.png")

Expand All @@ -32,7 +27,7 @@
image_graphic.cmap.vmin = 0.5
image_graphic.cmap.vmax = 0.75

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
fpl.run()
File renamed without changes.
8 changes: 5 additions & 3 deletions examples/line/line.py → examples/desktop/line/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

# test_example = true

from fastplotlib import Plot
import fastplotlib as fpl
import numpy as np


plot = Plot()
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(-10, 10, 100)
# sine wave
Expand Down Expand Up @@ -41,7 +43,7 @@

plot.auto_scale()

img = np.asarray(plot.renderer.target.draw())

if __name__ == "__main__":
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(-10, 10, 100)
# sine wave
Expand Down Expand Up @@ -43,4 +45,5 @@
plot.canvas.set_logical_size(800, 800)

if __name__ == "__main__":
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

# test_example = true

from fastplotlib import Plot
import fastplotlib as fpl
import numpy as np


plot = Plot()
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(-10, 10, 100)
# sine wave
Expand Down Expand Up @@ -64,3 +66,4 @@

if __name__ == "__main__":
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

# test_example = true

from fastplotlib import Plot
import fastplotlib as fpl
import numpy as np


plot = Plot()
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(-10, 10, 100)
# sine wave
Expand Down Expand Up @@ -53,3 +55,4 @@

if __name__ == "__main__":
print(__doc__)
fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

# test_example = true

from fastplotlib import Plot
import fastplotlib as fpl
import numpy as np


plot = Plot()
plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

xs = np.linspace(-10, 10, 100)
# sine wave
Expand Down Expand Up @@ -47,4 +49,4 @@

if __name__ == "__main__":
print(__doc__)

fpl.run()
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
pos_xy = np.vstack(circles)

plot = fpl.Plot()
# to force a specific framework such as glfw:
# plot = fpl.Plot(canvas="glfw")

plot.add_line_collection(circles, cmap="jet", thickness=5)

Expand All @@ -36,4 +38,5 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
plot.canvas.set_logical_size(800, 800)

if __name__ == "__main__":
print(__doc__)
fpl.run()
Loading