Skip to content
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

Add support for matplotlib issue #71 #115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carlosnid1
Copy link


name: Pull Request
about: Create a pull request to contribute to the project
title: "Add Support for Rendering Matplotlib Figures as a Component"
labels: "enhancement"
assignees: ''


Related Issue
Fixes #71

Description of Changes
This PR adds support for rendering Matplotlib figures as a component in the frontend. Users can now use preswald.matplotlib.plot() to generate plots, which will automatically render in the UI when running preswald run hello.py.

Changes Implemented

Backend

  • Updated preswald/components.py to support matplotlib.plot().
  • Converted matplotlib.figure.Figure into a frontend-compatible format (PNG, SVG, etc.).
  • Ensured serialization follows the existing structure.
  • Added tests to verify that Matplotlib figures are created, serialized, and transmitted properly.

Frontend

  • Added a new component in frontend/src/components/widgets/ to render Matplotlib figures.
  • Implemented logic to handle different image formats dynamically (PNG, SVG, etc.).
  • Ensured proper resizing and layout adjustments for responsiveness.

Integration

  • Updated DynamicComponents.jsx to recognize and render the Matplotlib component.
  • Successfully tested by running preswald run hello.py with a Matplotlib plot.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • New example
  • Test improvement

Testing

  • Verified that Matplotlib figures render correctly in the UI.
  • Confirmed that dynamic updates work when new figure data is provided.
  • Ensured that the changes do not break existing functionality.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have run my code against examples and ensured no errors
  • Any dependent changes have been merged and published in downstream modules

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.

[Components] Add support for matplotlib
1 participant