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 — Legend update_using_camera by uutzinger · Pull Request #835 · fastplotlib/fastplotlib

Conversation

@uutzinger

@uutzinger uutzinger commented May 21, 2025

Copy link
Copy Markdown

Updated legend.py:

  • added update_using_camera function which scales and places origin in dock
  • dock can be left,right, top, bottom
  • updated color handling (not fully tested)
  • updated legend padding

Example qt/lineplot.py

  • creates 3 traces in a lineplot and animates it
  • uses white background to plot black, red and blue demo traces
  • uses PyQt
  • utilizes legend
  • adjusts tick, grids, docks
  • measures displayed segments per second

gitignore

  • added _gallery

testing

  • Used black to update formatting
  • ran tests, some failed but not due to legend changes
  • python docs/source/generate_api.py because legend has now background color option

Sorry, something went wrong.

Uh oh!

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

All reactions
uutzinger and others added 10 commits May 20, 2025 19:03
@uutzinger
Legend updates for lineplot example
47f962f
Updated legend color handling and scaling
Provided PyQt lineplot example using black on white background
@uutzinger
Merge branch 'fastplotlib:main' into legend-pygfx-compat
591a593
@uutzinger
black legend.py reformat
eef7bf7
@uutzinger
python source/generate_api.py
a426bd8
@uutzinger
Removed intermediate docs build files
ab43c56
# delete docs/api dir
rm -rf docs/source/api

# delete _gallery dir
rm -rf docs/source/_gallery

# regenerate the API docs
python docs/source/generate_api.py
@uutzinger
Legend updates for lineplot example
5775afb
Updated legend color handling and scaling
Provided PyQt lineplot example using black on white background
@uutzinger
black legend.py reformat
a33487a
@uutzinger
python source/generate_api.py
9bda4e2
@uutzinger
Removed intermediate docs build files
6da34cc
# delete docs/api dir
rm -rf docs/source/api

# delete _gallery dir
rm -rf docs/source/_gallery

# regenerate the API docs
python docs/source/generate_api.py
@uutzinger
Merge branch 'legend-pygfx-compat' of https://github.com/uutzinger/fa…
b4d73c0
…stplotlib into legend-pygfx-compat
@uutzinger
uutzinger requested review from clewis7 and kushalkolar as code owners May 21, 2025 16:11
@kushalkolar

kushalkolar commented May 22, 2025

Copy link
Copy Markdown
Member

This looks like a great start! Do you want to implement more of what's in #403 or we'll just use this for now and implement the rest when we can.

I have a bunch of changes to make but I think it's easier if I edit your branch directly if you don't mind.

All reactions

Sorry, something went wrong.

Uh oh!

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

kushalkolar
kushalkolar requested changes May 22, 2025
View reviewed changes
Comment thread fastplotlib/legends/legend.py
Comment on lines +307 to +311
def update_using_camera(self):
"""
Update the legend position and scale using the camera.
This only works if legend is in a Dock, not a Plot or Subplot.
"""

@kushalkolar kushalkolar May 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be much easier after #830 is merged (by tomorrow) since it adds an overlay render pass.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread examples/qt/lineplot.py
)

# Subplot
self.ax = self.fig[0, 0]

@kushalkolar kushalkolar May 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just call these subplot instead of ax to conform with the rest of the examples, I can make these changes if you want

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread examples/qt/lineplot.py
Comment on lines +24 to +31
def rotate(angle, axis_x, axis_y, axis_z):
"""
Quaternion representing rotation around the given axis by the given angle.
"""
a2 = angle/2.0
c = cos(a2)
s = sin(a2)
return (axis_x * s, axis_y * s, axis_z * s, c)

@kushalkolar kushalkolar May 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, would be useful to have this in the addition to the existing Graphic.rotate

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread examples/qt/lineplot.py
Comment on lines +86 to +107
# X label
self.ax.docks["bottom"].size = 30
self.ax.docks["bottom"].add_text(
"X",
font_size=16,
face_color=(0, 0, 0, 1),
anchor="middle-center",
offset=(0, 0, 0),
)
self.ax.docks["bottom"].background_color = self.WHITE

# Y label
q = rotate(pi/2.0, 0., 0., 1.) # rotate 90 deg around z-axis
self.ax.docks["left"].size = 30
self.ax.docks["left"].add_text(
"Y",
font_size=16,
face_color=(0, 0, 0, 1),
anchor="middle-center",
offset=(0, 0, 0),
rotation=q,
)

@kushalkolar kushalkolar May 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pygfx will have seen soon, let's wait until we have the proper implementation pygfx/pygfx#739

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread examples/qt/lineplot.py
Comment on lines +76 to +84
self.ax.docks["top"].size = 30
self.ax.docks["top"].add_text(
"Line Plots",
font_size=16,
face_color=(0, 0, 0, 1),
anchor="middle-center",
offset=(0, 0, 0),
)
self.ax.docks["top"].background_color = self.WHITE

@kushalkolar kushalkolar May 22, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not subplot.title = "title"?

Sorry, something went wrong.

Uh oh!

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

All reactions
@kushalkolar

kushalkolar commented May 22, 2025

Copy link
Copy Markdown
Member

Nice work! I was taking a look at your repos, are you trying to create something like this https://github.com/uutzinger/SerialUI ? Curious to hear how fastplotlib has been working for your use case.

All reactions

Sorry, something went wrong.

Uh oh!

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

@uutzinger

uutzinger commented Jun 10, 2025

Copy link
Copy Markdown
Author

Nice work! I was taking a look at your repos, are you trying to create something like this https://github.com/uutzinger/SerialUI ? Curious to hear how fastplotlib has been working for your use case.

Yes that is why I am looking into fastplotlib. I hope to have some working prototype with fastplotlib shortly.

I have been trying to figure out what the advantage of fastplotlib might be compared to pyqtgraph which is what I am currently using.

  • It took a while to figure out how to make a "traditional" chart plot with fastplotlib, especially because there are limited examples for Qt and I had to first figure out which window manager configuration on ubuntu works for fastplotlib.
  • I made a simple test program for each graphics package that plots more or less the same line plots.
  • So far my conclusion is that fastplotlib does on my old mobile RTX3060 not provide more throughput but it has lower main thread cpu usage hopefully providing more capacity for my other qt threads.
  • Specifically flastplotlib has about 50% main thread cpu usage and pyqtgraph has about 80-90%. The number of line segments per second is slightly lower with fastplotlib compared to pyqtgraph.
  • It is not trivial to measure throughput with fastplotlib. The time it takes to generate new data, update the line plots with the new data and scheduling a refresh of the canvas is in my case less then10% of the update/loop time but GPU goes up to 75% on NVIDIA usage meter and plotting maxes out.
  • Also when I resize the display window, the update frame rate is becoming slower with fastplotlib, more so than with pqqtgraph.
    Urs
All reactions

Sorry, something went wrong.

Uh oh!

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

uutzinger and others added 2 commits June 9, 2025 22:35
@uutzinger
Update lineplot.py
15925d9
@uutzinger
Merge branch 'fastplotlib:main' into legend-pygfx-compat
cb33eda
@kushalkolar

kushalkolar commented Jun 10, 2025

Copy link
Copy Markdown
Member

Nice work! I was taking a look at your repos, are you trying to create something like this https://github.com/uutzinger/SerialUI ? Curious to hear how fastplotlib has been working for your use case.

Yes that is why I am looking into fastplotlib. I hope to have some working prototype with fastplotlib shortly.

I have been trying to figure out what the advantage of fastplotlib might be compared to pyqtgraph which is what I am currently using.

  • It took a while to figure out how to make a "traditional" chart plot with fastplotlib, especially because there are limited examples for Qt and I had to first figure out which window manager configuration on ubuntu works for fastplotlib.

We rely on the community for more detailed Qt examples, thanks for your contribution! We're not a Qt lib like pyqtgraph, wgpu can render to a anything that rendercanvas supports.

  • I made a simple test program for each graphics package that plots more or less the same line plots.
  • So far my conclusion is that fastplotlib does on my old mobile RTX3060 not provide more throughput but it has lower main thread cpu usage hopefully providing more capacity for my other qt threads.
  • Specifically flastplotlib has about 50% main thread cpu usage and pyqtgraph has about 80-90%. The number of line segments per second is slightly lower with fastplotlib compared to pyqtgraph.

How many lines are your plotting and how many points per line? Is your 3060 selected or integrated graphics?

  • It is not trivial to measure throughput with fastplotlib. The time it takes to generate new data, update the line plots with the new data and scheduling a refresh of the canvas is in my case less then10% of the update/loop time but GPU goes up to 75% on NVIDIA usage meter and plotting maxes out.

I'm hoping to make a benchmark for fastplotlib soon, you can take a look at the pygfx benchmarks for now: https://github.com/pygfx/pygfx-benchmarks

  • Also when I resize the display window, the update frame rate is becoming slower with fastplotlib, more so than with pqqtgraph.

I think the rendering is intentionally paused when the canvas is being resized.

All reactions

Sorry, something went wrong.

Uh oh!

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

@uutzinger

uutzinger commented Jun 10, 2025

Copy link
Copy Markdown
Author

Nice work! I was taking a look at your repos, are you trying to create something like this https://github.com/uutzinger/SerialUI ? Curious to hear how fastplotlib has been working for your use case.

Yes that is why I am looking into fastplotlib. I hope to have some working prototype with fastplotlib shortly.
I have been trying to figure out what the advantage of fastplotlib might be compared to pyqtgraph which is what I am currently using.

  • It took a while to figure out how to make a "traditional" chart plot with fastplotlib, especially because there are limited examples for Qt and I had to first figure out which window manager configuration on ubuntu works for fastplotlib.

We rely on the community for more detailed Qt examples, thanks for your contribution! We're not a Qt lib like pyqtgraph, wgpu can render to a anything that rendercanvas supports.

  • I made a simple test program for each graphics package that plots more or less the same line plots.
  • So far my conclusion is that fastplotlib does on my old mobile RTX3060 not provide more throughput but it has lower main thread cpu usage hopefully providing more capacity for my other qt threads.
  • Specifically flastplotlib has about 50% main thread cpu usage and pyqtgraph has about 80-90%. The number of line segments per second is slightly lower with fastplotlib compared to pyqtgraph.

How many lines are your plotting and how many points per line? Is your 3060 selected or integrated graphics?

  • It is not trivial to measure throughput with fastplotlib. The time it takes to generate new data, update the line plots with the new data and scheduling a refresh of the canvas is in my case less then10% of the update/loop time but GPU goes up to 75% on NVIDIA usage meter and plotting maxes out.

I'm hoping to make a benchmark for fastplotlib soon, you can take a look at the pygfx benchmarks for now: https://github.com/pygfx/pygfx-benchmarks

  • Also when I resize the display window, the update frame rate is becoming slower with fastplotlib, more so than with pqqtgraph.

I think the rendering is intentionally paused when the canvas is being resized.

Test Programs

3 x 50_000 line segments per frame
normal window size 800x600
full screen 2500x1400
PyQt6 Window
Generating = per cent of loop spent generating data

test_lineplot.zip

Hardware Options

  • NVIDIA 3060 notebook
  • Radeon, AMD Renoir (part of AMD Ryzen)
  • AMD Ryzen 7 4800H (used for CPU rendering)
  • OpenGL as provided by OS

Running on Ubuntu

FASTPLOTLIB Performance

Nividia 3060 Vulkan

Lines/s: 10,215,192, Interval: 1.011 Generating: 4.1% FPS: 63.40 Python Main Thread usage: 60.3%
Lines/s: 11,411,716, Interval: 1.022 Generating: 4.9% FPS: 71.35 Python Main Thread usage: 65.3%
Lines/s: 10,975,969, Interval: 1.007 Generating: 5.0% FPS: 66.59 Python Main Thread usage: 72.5%

fullscreen

Lines/s: 5,058,138, Interval: 1.048 Generating: 3.8% FPS: 31.27 Python Main Thread usage: 48.7%
Lines/s: 4,843,211, Interval: 1.032 Generating: 4.0% FPS: 29.50 Python Main Thread usage: 47.8%
Lines/s: 5,014,156, Interval: 1.057 Generating: 3.8% FPS: 30.68 Python Main Thread usage: 47.6%

Radeon Vulkan

Lines/s: 11,278,138, Interval: 1.007 Generating: 4.9% FPS: 75.57 Python Main Thread usage: 75.6%
Lines/s: 11,457,797, Interval: 1.022 Generating: 5.2% FPS: 67.99 Python Main Thread usage: 77.8%
Lines/s: 13,151,688, Interval: 1.010 Generating: 5.1% FPS: 81.19 Python Main Thread usage: 79.8%

fullscreen

Lines/s: 5,571,927, Interval: 1.055 Generating: 3.0% FPS: 34.26 Python Main Thread usage: 49.8%
Lines/s: 5,609,378, Interval: 1.051 Generating: 3.4% FPS: 34.76 Python Main Thread usage: 48.9%
Lines/s: 5,604,300, Interval: 1.001 Generating: 3.8% FPS: 37.45 Python Main Thread usage: 50.6%

CPU/LLVM Vulkan

Lines/s: 350,917, Interval: 1.715 Generating: 0.3% FPS: 2.33 Python Main Thread usage: 4.1%
Lines/s: 359,257, Interval: 1.673 Generating: 0.2% FPS: 2.32 Python Main Thread usage: 3.7%
Lines/s: 370,106, Interval: 1.624 Generating: 0.2% FPS: 2.32 Python Main Thread usage: 3.3%

fullscreen

Lines/s: 540,940, Interval: 1.112 Generating: 0.3% FPS: 3.39 Python Main Thread usage: 6.4%
Lines/s: 532,875, Interval: 1.129 Generating: 0.3% FPS: 3.38 Python Main Thread usage: 6.3%
Lines/s: 533,941, Interval: 1.126 Generating: 0.2% FPS: 3.38 Python Main Thread usage: 6.8%

Radeon OpenGL

Lines/s: 14,919,069, Interval: 1.010 Generating: 6.4% FPS: 88.10 Python Main Thread usage: 86.6%
Lines/s: 14,899,254, Interval: 1.014 Generating: 6.7% FPS: 90.26 Python Main Thread usage: 86.3%
Lines/s: 15,034,213, Interval: 1.004 Generating: 6.6% FPS: 88.11 Python Main Thread usage: 86.9%

fullscreen

Lines/s: 5,379,418, Interval: 1.041 Generating: 3.5% FPS: 32.88 Python Main Thread usage: 49.2%
Lines/s: 5,545,056, Interval: 1.003 Generating: 2.9% FPS: 33.93 Python Main Thread usage: 45.6%
Lines/s: 5,500,725, Interval: 1.009 Generating: 2.7% FPS: 34.04 Python Main Thread usage: 47.8%

PYQTGRAPH Performance

regular window

Lines/s: 6,333,290, Interval: 1.018 Generating: 2.3% FPS: 41.75 Python Main Thread usage: 82.8%
Lines/s: 6,436,724, Interval: 1.002 Generating: 2.3% FPS: 41.08 Python Main Thread usage: 82.9%
Lines/s: 6,183,019, Interval: 1.017 Generating: 2.2% FPS: 39.36 Python Main Thread usage: 81.7%

full screen

Lines/s: 2,195,240, Interval: 1.033 Generating: 0.8% FPS: 14.54 Python Main Thread usage: 72.9%
Lines/s: 2,227,183, Interval: 1.018 Generating: 0.8% FPS: 14.76 Python Main Thread usage: 73.1%
Lines/s: 2,243,544, Interval: 1.011 Generating: 0.8% FPS: 14.83 Python Main Thread usage: 73.1%

All reactions

Sorry, something went wrong.

Uh oh!

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

@kushalkolar

kushalkolar commented Jun 20, 2025

Copy link
Copy Markdown
Member

Thanks for the example, we're a bit busy with other projects at the moment so I'll incorporate your changes next month.

All reactions

Sorry, something went wrong.

Uh oh!

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

uutzinger added 2 commits September 24, 2025 08:21
@uutzinger
Sync image_widget_grid.png with main
5649116
@uutzinger
Merge remote-tracking branch 'origin/main' into legend-pygfx-compat
e371cc7
@uutzinger

uutzinger commented Oct 6, 2025

Copy link
Copy Markdown
Author

legend.py
I proposed previously some changes the legend.py so that I can specify background color and I added a function so that the legend adjusts with custom update_using_camera call. In attached file I also added option to change text color for the legend. There were some recent changes made to enable pygfx 0.13.0 and I included these changes in the attached legend,py also but since I run release v0.5.1 version, I used try/except blocks so that it works on latest updates on github as well as 0.5.1. I believe you wanted to wait for some other changes to occur first before considering my suggestions. It would help me to be able to specify to background color of the legend and the color of the legend text. Also a function that works like my proposed update_using_camera would be helpful. If you like me to try a different approach to contribute to legend code let me know please.

All reactions

Sorry, something went wrong.

Uh oh!

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

@kushalkolar

kushalkolar commented Oct 6, 2025

Copy link
Copy Markdown
Member

Hi sorry I haven't had time to follow up on this. We're pretty busy with other low level priorities at the moment.

If you'd like to contribute to a fully-fledged legend we outlined our ideas here, some of the ideas do need to be updated w.r.t. recent improvement in pygfx & fpl: #403

Legends should go in the overlay render pass that was introduced in #830, so updating with camera changes won't be necessary.

I'm not sure if we still want to do a separate colorbar when colormaps are used for lines, it may make sense to derive something from the existing HistogramLUTTool.

All reactions

Sorry, something went wrong.

Uh oh!

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

@uutzinger

uutzinger commented Oct 31, 2025

Copy link
Copy Markdown
Author

This is as far as I got with fastplotlib in my charting app: Recording made for this response (on youtube) The legend placing could be improved but runs with latest fpl from github.

The way it looks like with pyqtgraph can be seen in the app repo https://github.com/uutzinger/SerialUI.

The updated legends.py I use is in https://github.com/uutzinger/SerialUI/tree/main/Python_libraries/fastplotlib/legends
The description in basics section items in #403 work.
I did not work on colorbar for lines.

The charting in my application works similar to Electromagnetic Wave Animation in your Examples.

All reactions

Sorry, something went wrong.

Uh oh!

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

@kushalkolar

kushalkolar commented Sep 22, 2026

Copy link
Copy Markdown
Member

we decided to just use imgui for legends, #1088 , will be in the new release this week.

uutzinger reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@kushalkolar kushalkolar closed this Sep 22, 2026
@uutzinger

uutzinger commented Sep 22, 2026

Copy link
Copy Markdown
Author

Thanks for letting me know.

All reactions

Sorry, something went wrong.

Uh oh!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kushalkolar kushalkolar kushalkolar requested changes
@clewis7 clewis7 Awaiting requested review from clewis7 clewis7 is a code owner

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

@uutzinger @kushalkolar
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.