GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Imgui legend by kushalkolar · Pull Request #1088 · fastplotlib/fastplotlib

Conversation

@kushalkolar

@kushalkolar kushalkolar commented Sep 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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"
)
image

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",
            },
        )
    ]
)
image

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,
)
image

LLM Disclosure

I'm sorry

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kushalkolar
kushalkolar requested a review from FlynnOConnell September 22, 2026 06:31
@kushalkolar
kushalkolar requested a review from clewis7 as a code owner September 22, 2026 06:31
@kushalkolar kushalkolar mentioned this pull request Sep 22, 2026
Legend update_using_camera #835
Closed
@kushalkolar
kushalkolar changed the base branch from main to api-docs-gen September 22, 2026 07:47
@kushalkolar
kushalkolar added this pull request to stack #1089 September 22, 2026 07:47
@kushalkolar
kushalkolar force-pushed the imgui-legend branch from de3401c to e1dd41a Compare September 22, 2026 07:47
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown

📚 Docs preview built and uploaded! https://www.fastplotlib.org/ver/imgui-legend

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Base automatically changed from api-docs-gen to main September 22, 2026 13:44
kushalkolar added 6 commits September 22, 2026 09:45
@kushalkolar @clewis7
basics work
721f1c8
@kushalkolar @clewis7
example
e8d264d
@kushalkolar @clewis7
examles
413704f
@kushalkolar @clewis7
update
811c1d4
@kushalkolar @clewis7
add legend test screenshots
1c0ced0
@kushalkolar @clewis7
docs
f87d13a
@clewis7
clewis7 force-pushed the imgui-legend branch from e1dd41a to f87d13a Compare September 22, 2026 13:45
clewis7
clewis7 approved these changes Sep 22, 2026
View reviewed changes
@kushalkolar
kushalkolar merged commit 245f715 into main Sep 22, 2026
36 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kushalkolar
kushalkolar deleted the imgui-legend branch October 8, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@clewis7 clewis7 clewis7 approved these changes
@FlynnOConnell FlynnOConnell Awaiting requested review from FlynnOConnell

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@kushalkolar @clewis7
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.