GeezerVison is showing github.com — Imgui legend by kushalkolar · Pull Request #1088 · fastplotlib/fastplotlib
Conversation
kushalkolar
commented
Sep 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Legends, using imgui to manage the legend items. No support for collections for now, will do that later. But you can create a LegendItem for each graphic in a collection.
Line
sine = figure[0, 0].add_line(np.column_stack([xs, np.sin(xs)]), colors="w", name="sine")
cosine = figure[0, 0].add_line(
np.column_stack([xs, np.cos(xs)]), colors="cyan", name="cosine"
)
# vertical lines at every half period
phase = figure[0, 0].add_inf_line(
np.arange(0, 4.5 * np.pi, np.pi / 2, dtype=np.float32),
axis="x",
colors="gray",
thickness=1,
dash_pattern="--",
name="phase",
)
# a graphic with one color is one entry, labelled by the graphic's name
legend = Legend(
[
sine.create_legend_item(),
cosine.create_legend_item(),
phase.create_legend_item(),
]
)
figure.add_imgui_window(
legend, location="floating", rect=(0.8, 0.05, 0, 0), title="legend"
)
Scatter
# one marker shape per predicted cluster
kmeans = KMeans(n_clusters=3, n_init=10, random_state=0).fit(iris["data"])
markers = np.asarray(["circle", "square", "diamond"])[kmeans.labels_]
scatter = figure[0, 0].add_scatter(
data=iris["data"][:, :2], # sepal length and width
sizes=12,
cmap="tab10",
cmap_transform=iris["target"], # species
markers=markers,
alpha=0.5,
)
# qualitative colormap, span its full range so that species k always gets color k
scatter.cmap_range = (0, scatter.cmap.num_colors)
# the species entries are colored by the colormap, the cluster entries show the marker shapes
legend = Legend(
[
scatter.create_legend_item(
label="iris",
cmap_transform_labels={
i: str(name) for i, name in enumerate(iris["target_names"])
},
markers_labels={
"circle": "cluster 0",
"square": "cluster 1",
"diamond": "cluster 2",
},
)
]
)
Colorbar for line and scatter cmaps:
sine = figure["sine"].add_line(
np.column_stack([xs, ys]),
cmap="matplotlib:coolwarm",
cmap_transform=ys,
thickness=5,
)
figure["sine"].add_imgui_window(
ImguiColorbar(graphics=sine, title="sin(x)"), location="right", size=80
)
# a 2d gaussian blob colored by the distance of each point from the origin, with the distribution
# of those distances drawn on the colorbar
rng = np.random.default_rng(0)
points = rng.normal(0, 1, (5_000, 2)).astype(np.float32)
radius = np.linalg.norm(points, axis=1)
blob = figure["gaussian"].add_scatter(
points,
cmap="bids:viridis",
cmap_transform=radius,
sizes=4,
)
figure["gaussian"].add_imgui_window(
ImguiColorbar(
graphics=blob,
title="radius",
histogram=np.histogram(radius, bins=100),
),
location="right",
size=100,
)
LLM Disclosure
I'm sorry
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
clewis7
clewis7 approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|