Skip to content

feat: support subplots in py-maidr using maidr-ts #147

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 9 commits into from
Mar 18, 2025
Merged

Conversation

dakshpokar
Copy link
Collaborator

@dakshpokar dakshpokar commented Mar 14, 2025

Description

This PR address the subplots feature that is supported in maidr-ts using (https://github.com/xability/maidr-ts/pull/130) by restructuring the Maidr Object in a proper structure way. This change implements grid layout support for the TypeScript rendering engine within the _flatten_maidr method. The implementation transforms plot schemas into a structured grid format where each cell can contain multiple plot layers. The code calculates maximum row and column dimensions, groups plots by position coordinates, arranges them into appropriate grid cells, and assigns unique IDs to each subplot. This structured approach enables complex multi-plot layouts in the TypeScript engine while maintaining proper spatial relationships between subplots. The result is a hierarchical JSON structure with an outer container ID and a nested grid of subplots, each containing their respective visualization layers.

P.S.: This change will continue to support MaidrJS Engine.

Type of Change

  • Bug fix
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

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

@dakshpokar dakshpokar changed the title feat: support multipanel plots in py-maidr using maidr-ts feat: support subplots in py-maidr using maidr-ts Mar 14, 2025
@dakshpokar
Copy link
Collaborator Author

dakshpokar commented Mar 14, 2025

Professor @jooyoungseo & @SaaiVenkat,
This PR introduces support for subplots. Please note that the current implementation in the py-maidr package using the maidr-ts engine supports only line and bar plots. As a result, the included multipanel example consists of one line plot and two bar plots. Future PRs will add support for additional plot types, after which the examples will be updated accordingly.

Additionally, facet plots have not yet been tested. It's possible facet plots may require further adjustments or fixes. However, to facilitate prompt feedback and review, I'm submitting this PR now. Once facet plots have been tested, I'll either update this PR with the corresponding example or open a new PR if significant changes are required.

Thank you,
DP

@jooyoungseo jooyoungseo requested a review from Copilot March 14, 2025 09:45
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 implements support for subplots in the maidr-ts rendering engine by restructuring the Maidr object to build a grid layout that supports multiple plot layers. Key changes include:

  • Refactoring the _flatten_maidr method to organize plots into a grid with row and column indices.
  • Updates to example scripts across seaborn, matplotlib, and multilayer examples to demonstrate the new subplot and multilayer capabilities.
  • Minor modifications in related modules, such as API adjustments and patch updates for bar and scatter plots.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
example/multipanel/seaborn/example_sns_multipanel.py New multipanel seaborn example script.
example/multipanel/matplotlib/example_mpl_multipanel.py New multipanel matplotlib example script with a typo fix.
example/multilayer/example_mpl_multilayer.py New multilayer example script demonstrating dual-axis plots.
maidr/core/maidr.py Updates to flatten Maidr layout for TS engine and minor import adjustments.
maidr/patch/barplot.py Adjustments to plotting behavior for bar charts.
maidr/util/mixin/extractor_mixin.py Updates to tick extraction logic for improved data handling.
maidr/api.py Enhancements to support multiple axes in the show and save_html functions.
example/stacked/matplotlib/example_mpl_stacked.py Updated labels and layout for stacked matplotlib example.
maidr/core/plot/barplot.py Fixes in data extraction logic for TS engine compatibility.
maidr/core/plot/maidr_plot.py Adding subplot indexing from the subplotspec for grid layouts.
maidr/patch/scatterplot.py Minor formatting cleanup.
Comments suppressed due to low confidence (1)

maidr/patch/barplot.py:55

  • [nitpick] The updated branch in the bar function removes the numeric type check for 'x' positions; if this change is not intentional, consider reinstating the check to correctly determine a dodged bar plot, or update the documentation to reflect the new behavior.
else:

@dakshpokar
Copy link
Collaborator Author

Referencing an additional PR that adds supports for facet plots
#148

Copy link
Member

@jooyoungseo jooyoungseo left a comment

Choose a reason for hiding this comment

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

LGTM!

@jooyoungseo
Copy link
Member

@dakshpokar Please address the branch conflict and merge.

@dakshpokar
Copy link
Collaborator Author

Merging this!

@dakshpokar dakshpokar merged commit 5349f63 into main Mar 18, 2025
9 checks passed
@dakshpokar dakshpokar deleted the feat/multipanel branch March 18, 2025 21: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.

2 participants