Skip to content

Migrate from MatPlotLib to PyQtGraph to plot data #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 8, 2025

Conversation

Giulero
Copy link
Contributor

@Giulero Giulero commented Apr 14, 2025

This PR introduces the use of PyQtGraph to plot the data. Ideally, this can be used in place of matplotlib for faster execution and might be used for real-time logging, see #80.

Screenshot from 2025-04-14 17-12-20

New functionality:

Enhancements to existing functionality:

@Giulero Giulero self-assigned this Apr 14, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new PyQtGraph canvas component to plot data in real-time, replacing matplotlib for improved performance in real-time logging. Key changes include:

  • Adding the PyQtGraphViewerCanvas class with plotting, animation, and annotation functionality.
  • Enhancing color_palette by enabling it to be used as a callable to retrieve colors.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
robot_log_visualizer/plotter/pyqtgraph_viewer_canvas.py New canvas class using PyQtGraph with animation and annotation.
robot_log_visualizer/plotter/color_palette.py Added a call method to retrieve colors via a callable interface.
Comments suppressed due to low confidence (1)

robot_log_visualizer/plotter/pyqtgraph_viewer_canvas.py:3

  • Duplicate import of 'pyqtgraph' detected. Please remove the redundant import statement to keep the code clean and avoid potential confusion.
import pyqtgraph as pg

@traversaro
Copy link
Contributor

I guess we need to add pyqtgraph to the dependencies in

install_requires =
?

@GiulioRomualdi
Copy link
Member

I guess we need to add pyqtgraph to the dependencies in

install_requires =
?

Yes! In the future, we can also move to the toml configuration

Copy link
Contributor Author

@Giulero Giulero left a comment

Choose a reason for hiding this comment

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

I guess we need to add pyqtgraph to the dependencies in

install_requires =
?

Sure! Done with d3ef505

@Giulero Giulero marked this pull request as ready for review April 15, 2025 08:31
@Giulero
Copy link
Contributor Author

Giulero commented Apr 15, 2025

For now in 1772740 i substituted the MaplotlibViewerCanvas with the PyQtGraphViewerCanvas, but with could think of a logic that allows the user to choose one or another.

1 similar comment
@Giulero

This comment was marked as duplicate.

Giulero

This comment was marked as duplicate.

@Giulero Giulero requested a review from Copilot April 15, 2025 08:33
Copilot

This comment was marked as outdated.

@GiulioRomualdi
Copy link
Member

We can try to work on this and see if we can merge by few days

@GiulioRomualdi GiulioRomualdi requested a review from Copilot June 28, 2025 10:40
Copilot

This comment was marked as outdated.

@GiulioRomualdi
Copy link
Member

I noticed that while clicking on the point in the dataset just the label is shown and not the circle

@GiulioRomualdi
Copy link
Member

@traversaro when this Will be merge (hopefully) we need to add a new dependency in the superbuild. Do you think Is problematic? How can we handle this?

@traversaro
Copy link
Contributor

@traversaro when this Will be merge (hopefully) we need to add a new dependency in the superbuild. Do you think Is problematic? How can we handle this?

It seems available in conda-forge https://anaconda.org/conda-forge/pyqtgraph and apt https://repology.org/project/python:pyqtgraph/versions, so I think we are good to go.

@GiulioRomualdi GiulioRomualdi requested a review from Copilot July 8, 2025 17:37
@GiulioRomualdi GiulioRomualdi changed the title Use PyQtGraph to plot data Migrate from MatPlotLib to PyQtGraph to plot data Jul 8, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces the Matplotlib-based plot canvas with a PyQtGraph implementation to speed up rendering and enable real-time logging, and updates the UI to use the new viewer.

  • Adds PyQtGraphViewerCanvas for interactive, animated time-series plotting.
  • Removes the old MatplotlibViewerCanvas.
  • Updates dependencies and UI code to wire in the new canvas and add a space-bar play/pause toggle.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
setup.cfg Added pyqtgraph to install requirements
robot_log_visualizer/ui/plot_item.py Swapped out MatplotlibViewerCanvas for PyQtGraphViewerCanvas
robot_log_visualizer/ui/gui.py Added space-bar handler in keyPressEvent to toggle play/pause
robot_log_visualizer/plotter/pyqtgraph_viewer_canvas.py Introduced new PyQtGraphViewerCanvas class
robot_log_visualizer/plotter/matplotlib_viewer_canvas.py Removed legacy Matplotlib-based canvas
robot_log_visualizer/plotter/color_palette.py Added __call__ method to ColorPalette
Comments suppressed due to low confidence (1)

robot_log_visualizer/plotter/pyqtgraph_viewer_canvas.py:71

  • Add unit or integration tests for PyQtGraphViewerCanvas (e.g., update_plots, mouse‐click annotation) to ensure new plotting behaviors are covered and regressions are caught.
    def update_plots(self, paths: Sequence[Path], legends: Sequence[Legend]) -> None:

@@ -48,6 +48,7 @@ install_requires =
pyqtconsole
matplotlib
h5py
pyqtgraph
Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider pinning the pyqtgraph dependency to a specific version range to avoid unintentional breakage from upstream API changes.

Suggested change
pyqtgraph
pyqtgraph >=0.12.0, <0.13.0

Copilot uses AI. Check for mistakes.

@@ -308,6 +308,15 @@ def keyPressEvent(self, event):

self.ui.timeSlider.setValue(new_index)
self.slider_pressed = False
else:
Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

After handling Left/Right arrows and Space, add a super().keyPressEvent(event) fallback so that other key events continue to behave as expected.

Copilot uses AI. Check for mistakes.

@GiulioRomualdi GiulioRomualdi merged commit a7505ae into main Jul 8, 2025
9 checks passed
@GiulioRomualdi GiulioRomualdi deleted the add_pyqtgraph_plotting branch July 8, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants