Skip to content

Commit bb2e717

Browse files
authored
Update examples (#261)
* heatmap and lines cmap nb * update simple.ipynb * move nb examples * simplify examples * move test examples to desktop dir * update CI * update README * add tqdm to test requirements
1 parent f85a71e commit bb2e717

Some content is hidden

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

64 files changed

+490
-150
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ jobs:
6161
PYGFX_EXPECT_LAVAPIPE: true
6262
run: |
6363
pytest -v examples
64-
pytest --nbmake notebooks/
64+
pytest --nbmake examples/notebooks/
6565
- uses: actions/upload-artifact@v3
6666
if: ${{ failure() }}
6767
with:
6868
name: screenshot-diffs
69-
path: examples/diffs
69+
path: examples/desktop/diffs

.github/workflows/screenshots.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
if: always()
4949
with:
5050
name: screenshots
51-
path: examples/screenshots/
51+
path: examples/desktop/screenshots/

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,37 @@ pip install -e ".[notebook,docs,tests]"
7777
>
7878
> `fastplotlib` and `pygfx` are fast evolving, you may require the latest `pygfx` and `fastplotlib` from github to use the examples in the master branch.
7979
80-
Clone or download the repo to try the examples
80+
First clone or download the repo to try the examples
8181

8282
```bash
83-
# clone the repo
8483
git clone https://github.com/kushalkolar/fastplotlib.git
84+
```
85+
86+
### Desktop examples using `glfw` or `Qt`
8587

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

90-
# cd into notebooks and launch jupyter lab
91-
cd fastplotlib/notebooks
92+
# simplest example
93+
python image/image_simple.py
94+
```
95+
96+
### Notebook examples
97+
98+
```bash
99+
cd examples/notebooks
92100
jupyter lab
93101
```
94102

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

97105
### Simple image plot
98106
```python
99-
from fastplotlib import Plot
107+
import fastplotlib as fpl
100108
import numpy as np
101109

102-
plot = Plot()
110+
plot = fpl.Plot()
103111

104112
data = np.random.rand(512, 512)
105113
plot.add_image(data=data)
@@ -110,10 +118,10 @@ plot.show()
110118

111119
### Fast animations
112120
```python
113-
from fastplotlib import Plot
121+
import fastplotlib as fpl
114122
import numpy as np
115123

116-
plot = Plot()
124+
plot = fpl.Plot()
117125

118126
data = np.random.rand(512, 512)
119127
image = plot.image(data=data)

examples/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

examples/gridplot/gridplot.py renamed to examples/desktop/gridplot/gridplot.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66

77
# test_example = true
88

9-
from fastplotlib import GridPlot
10-
import numpy as np
9+
import fastplotlib as fpl
1110
import imageio.v3 as iio
1211

13-
from wgpu.gui.offscreen import WgpuCanvas
14-
from pygfx import WgpuRenderer
1512

16-
canvas = WgpuCanvas()
17-
renderer = WgpuRenderer(canvas)
18-
19-
plot = GridPlot(shape=(2,2), canvas=canvas, renderer=renderer)
13+
plot = fpl.GridPlot(shape=(2, 2))
14+
# to force a specific framework such as glfw:
15+
# plot = fpl.GridPlot(canvas="glfw")
2016

2117
im = iio.imread("imageio:clock.png")
2218
im2 = iio.imread("imageio:astronaut.png")
@@ -35,7 +31,6 @@
3531
for subplot in plot:
3632
subplot.auto_scale()
3733

38-
img = np.asarray(plot.renderer.target.draw())
39-
4034
if __name__ == "__main__":
4135
print(__doc__)
36+
fpl.run()
File renamed without changes.

examples/image/image_cmap.py renamed to examples/desktop/image/image_cmap.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
"""
66
# test_example = true
77

8-
from fastplotlib import Plot
9-
import numpy as np
8+
import fastplotlib as fpl
109
import imageio.v3 as iio
1110

12-
from wgpu.gui.offscreen import WgpuCanvas
13-
from pygfx import WgpuRenderer
1411

15-
canvas = WgpuCanvas()
16-
renderer = WgpuRenderer(canvas)
17-
18-
plot = Plot(canvas=canvas, renderer=renderer)
12+
plot = fpl.Plot()
13+
# to force a specific framework such as glfw:
14+
# plot = fpl.Plot(canvas="glfw")
1915

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

@@ -30,7 +26,6 @@
3026

3127
image_graphic.cmap = "viridis"
3228

33-
img = np.asarray(plot.renderer.target.draw())
34-
3529
if __name__ == "__main__":
3630
print(__doc__)
31+
fpl.run()

examples/image/image_rgb.py renamed to examples/desktop/image/image_rgb.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
"""
66
# test_example = true
77

8-
from fastplotlib import Plot
9-
import numpy as np
8+
import fastplotlib as fpl
109
import imageio.v3 as iio
1110

12-
from wgpu.gui.offscreen import WgpuCanvas
13-
from pygfx import WgpuRenderer
1411

15-
canvas = WgpuCanvas()
16-
renderer = WgpuRenderer(canvas)
17-
18-
plot = Plot(canvas=canvas, renderer=renderer)
12+
plot = fpl.Plot()
13+
# to force a specific framework such as glfw:
14+
# plot = fpl.Plot(canvas="glfw")
1915

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

@@ -28,7 +24,7 @@
2824

2925
plot.auto_scale()
3026

31-
img = np.asarray(plot.renderer.target.draw())
3227

3328
if __name__ == "__main__":
34-
print(__doc__)
29+
print(__doc__)
30+
fpl.run()

0 commit comments

Comments
 (0)