Skip to content

Commit 20c9421

Browse files
kushalkolarclewis7almarklein
authored
Rectangle/bbox layouts in a Figure (#740)
* start basic mesh and camera stuff * progress * resizing canvas auto-resizes bboxes using internal fractional bbox * resizing works well * ranges as array, comments * layout management logic works! :D git status * handler color, size * cleanup * resize handler highlight * subplot title works, rename to Frame * start generalizing layout manager * cleaner * start rect and extent class for organization * start moving rect logic to a dedicated class * organization * better extent validation * progress * progress * progress * almost there * formatting, subplot toolbar tweaks * cleanup * docks * more stuff * grid works * add or remove subplot, not tested * better highlight behavior * increase size of example fig * repr * sdf for resize handle, better resize handle, overlap stuff with distance * cleanup * more space * spacing tweaks * add utils._types * unit circle using extents * black * refactor, better organization * modified: scripts/generate_add_graphic_methods.py * more stuff * more * add examples * black * rename * update test utils * update nb test utils * update ground truths * update nb ground truths * flex layouts examples 'as screenshot tests * accidentaly added screenshot * comments, cleanup * docs api * black * fix * cleanup * add README.rst for flex layouts examples dir * add flex layouts to test utils list * add spinning spiral scatter example * modify docs conf * forgot a comma * add rect extent ground truths * fix text * fix text features * types * comments, docstrings * update w.r.t. text changes * small typos # Conflicts: # fastplotlib/layouts/_engine.py * small typos * Update fastplotlib/layouts/_engine.py Co-authored-by: Almar Klein <almar@almarklein.org> * rename FlexLayout -> WindowLayout * better check for imgui * imports * comments * example tests files moved * smaller canvas initial size for abs pixels until rendercanvs fix for glfw * better error messages * update screenshots * update screenshots * black * newer black really was an extra comma for some reason * update example * underline * docstring, better exception messages --------- Co-authored-by: clewis7 <caitlin9165@gmail.com> Co-authored-by: Almar Klein <almar@almarklein.org>
1 parent 12ef40d commit 20c9421

151 files changed

Lines changed: 1999 additions & 615 deletions

File tree

Some content is hidden

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

‎docs/source/api/layouts/figure.rst‎

Lines changed: 3 additions & 2 deletions

‎docs/source/api/layouts/imgui_figure.rst‎

Lines changed: 3 additions & 2 deletions

‎docs/source/api/layouts/subplot.rst‎

Lines changed: 2 additions & 2 deletions

‎docs/source/conf.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"../../examples/heatmap",
6060
"../../examples/image_widget",
6161
"../../examples/gridplot",
62+
"../../examples/window_layouts",
6263
"../../examples/line",
6364
"../../examples/line_collection",
6465
"../../examples/scatter",

‎examples/image_widget/image_widget_videos.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
[random_data, cockatoo_sub],
3030
rgb=[False, True],
3131
figure_shape=(2, 1), # 2 rows, 1 column
32-
figure_kwargs={"size": (700, 560)}
32+
figure_kwargs={"size": (700, 940)}
3333
)
3434

3535
iw.show()

‎examples/machine_learning/kmeans.py‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
===================================
44
55
Example showing how you can perform K-Means clustering on the MNIST dataset.
6+
7+
Use WASD keys on your keyboard to fly through the data in PCA space.
8+
Use the mouse pointer to select points.
69
"""
710

811
# test_example = false
@@ -29,17 +32,17 @@
2932
# iterate through each subplot
3033
for i, subplot in enumerate(fig_data):
3134
# reshape each image to (8, 8)
32-
subplot.add_image(data[i].reshape(8,8), cmap="gray", interpolation="linear")
35+
subplot.add_image(data[i].reshape(8, 8), cmap="gray", interpolation="linear")
3336
# add the label as a title
34-
subplot.set_title(f"Label: {labels[i]}")
37+
subplot.title = f"Label: {labels[i]}"
3538
# turn off the axes and toolbar
3639
subplot.axes.visible = False
37-
subplot.toolbar = False
40+
subplot.toolbar = False
3841

3942
fig_data.show()
4043

4144
# project the data from 64 dimensions down to the number of unique digits
42-
n_digits = len(np.unique(labels)) # 10
45+
n_digits = len(np.unique(labels)) # 10
4346

4447
reduced_data = PCA(n_components=n_digits).fit_transform(data) # (1797, 10)
4548

@@ -53,17 +56,17 @@
5356

5457
# plot the kmeans result and corresponding original image
5558
figure = fpl.Figure(
56-
shape=(1,2),
57-
size=(700, 400),
59+
shape=(1, 2),
60+
size=(700, 560),
5861
cameras=["3d", "2d"],
59-
controller_types=[["fly", "panzoom"]]
62+
controller_types=["fly", "panzoom"]
6063
)
6164

62-
# set the axes to False
63-
figure[0, 0].axes.visible = False
65+
# set the axes to False in the image subplot
6466
figure[0, 1].axes.visible = False
6567

66-
figure[0, 0].set_title(f"K-means clustering of PCA-reduced data")
68+
figure[0, 0].title = "k-means clustering of PCA-reduced data"
69+
figure[0, 1].title = "handwritten digit"
6770

6871
# plot the centroids
6972
figure[0, 0].add_scatter(
@@ -94,6 +97,7 @@
9497
digit_scatter.colors[ix] = "magenta"
9598
digit_scatter.sizes[ix] = 10
9699

100+
97101
# define event handler to update the selected data point
98102
@digit_scatter.add_event_handler("pointer_enter")
99103
def update(ev):
@@ -110,8 +114,10 @@ def update(ev):
110114
# update digit fig
111115
figure[0, 1]["digit"].data = data[ix].reshape(8, 8)
112116

117+
113118
figure.show()
114119

120+
115121
# NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively
116122
# please see our docs for using fastplotlib interactively in ipython and jupyter
117123
if __name__ == "__main__":

‎examples/notebooks/nb_test_utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def plot_test(name, fig: fpl.Figure):
102102
# hacky but it works for now
103103
fig.imgui_renderer.render()
104104

105-
fig._set_viewport_rects()
105+
fig._fpl_reset_layout()
106106
# render each subplot
107107
for subplot in fig:
108108
subplot.viewport.render(subplot.scene, subplot.camera)
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)