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

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

Lines changed: 5 additions & 9 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

@@ -31,7 +27,7 @@
3127
image_graphic.cmap.vmin = 0.5
3228
image_graphic.cmap.vmax = 0.75
3329

34-
img = np.asarray(plot.renderer.target.draw())
3530

3631
if __name__ == "__main__":
3732
print(__doc__)
33+
fpl.run()

examples/image/image_simple.py renamed to examples/desktop/image/image_simple.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 Plot
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 = Plot(canvas=canvas, renderer=renderer)
13+
plot = fpl.Plot()
14+
# to force a specific framework such as glfw:
15+
# plot = fpl.Plot(canvas="glfw")
2016

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

@@ -29,7 +25,6 @@
2925

3026
plot.auto_scale()
3127

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

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

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

8-
from fastplotlib import Plot
9-
import numpy as np
10-
from pathlib import Path
8+
import fastplotlib as fpl
119
import imageio.v3 as iio
1210

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

16-
canvas = WgpuCanvas()
17-
renderer = WgpuRenderer(canvas)
18-
19-
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")
2015

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

@@ -32,7 +27,7 @@
3227
image_graphic.cmap.vmin = 0.5
3328
image_graphic.cmap.vmax = 0.75
3429

35-
img = np.asarray(plot.renderer.target.draw())
3630

3731
if __name__ == "__main__":
3832
print(__doc__)
33+
fpl.run()
File renamed without changes.

examples/line/line.py renamed to examples/desktop/line/line.py

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

77
# test_example = true
88

9-
from fastplotlib import Plot
9+
import fastplotlib as fpl
1010
import numpy as np
1111

1212

13-
plot = Plot()
13+
plot = fpl.Plot()
14+
# to force a specific framework such as glfw:
15+
# plot = fpl.Plot(canvas="glfw")
1416

1517
xs = np.linspace(-10, 10, 100)
1618
# sine wave
@@ -41,7 +43,7 @@
4143

4244
plot.auto_scale()
4345

44-
img = np.asarray(plot.renderer.target.draw())
4546

4647
if __name__ == "__main__":
4748
print(__doc__)
49+
fpl.run()

examples/line/line_cmap.py renamed to examples/desktop/line/line_cmap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212

1313
plot = fpl.Plot()
14+
# to force a specific framework such as glfw:
15+
# plot = fpl.Plot(canvas="glfw")
1416

1517
xs = np.linspace(-10, 10, 100)
1618
# sine wave
@@ -43,4 +45,5 @@
4345
plot.canvas.set_logical_size(800, 800)
4446

4547
if __name__ == "__main__":
48+
print(__doc__)
4649
fpl.run()

examples/line/line_colorslice.py renamed to examples/desktop/line/line_colorslice.py

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

77
# test_example = true
88

9-
from fastplotlib import Plot
9+
import fastplotlib as fpl
1010
import numpy as np
1111

1212

13-
plot = Plot()
13+
plot = fpl.Plot()
14+
# to force a specific framework such as glfw:
15+
# plot = fpl.Plot(canvas="glfw")
1416

1517
xs = np.linspace(-10, 10, 100)
1618
# sine wave
@@ -64,3 +66,4 @@
6466

6567
if __name__ == "__main__":
6668
print(__doc__)
69+
fpl.run()

examples/line/line_dataslice.py renamed to examples/desktop/line/line_dataslice.py

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

77
# test_example = true
88

9-
from fastplotlib import Plot
9+
import fastplotlib as fpl
1010
import numpy as np
1111

1212

13-
plot = Plot()
13+
plot = fpl.Plot()
14+
# to force a specific framework such as glfw:
15+
# plot = fpl.Plot(canvas="glfw")
1416

1517
xs = np.linspace(-10, 10, 100)
1618
# sine wave
@@ -53,3 +55,4 @@
5355

5456
if __name__ == "__main__":
5557
print(__doc__)
58+
fpl.run()

examples/line/line_present_scaling.py renamed to examples/desktop/line/line_present_scaling.py

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

77
# test_example = true
88

9-
from fastplotlib import Plot
9+
import fastplotlib as fpl
1010
import numpy as np
1111

1212

13-
plot = Plot()
13+
plot = fpl.Plot()
14+
# to force a specific framework such as glfw:
15+
# plot = fpl.Plot(canvas="glfw")
1416

1517
xs = np.linspace(-10, 10, 100)
1618
# sine wave
@@ -47,4 +49,4 @@
4749

4850
if __name__ == "__main__":
4951
print(__doc__)
50-
52+
fpl.run()

examples/line_collection/line_collection.py renamed to examples/desktop/line_collection/line_collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
2828
pos_xy = np.vstack(circles)
2929

3030
plot = fpl.Plot()
31+
# to force a specific framework such as glfw:
32+
# plot = fpl.Plot(canvas="glfw")
3133

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

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

3840
if __name__ == "__main__":
41+
print(__doc__)
3942
fpl.run()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy