Skip to content

feat: support facet plot in py-maidr using maidr-ts #148

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 24 commits into from
Apr 29, 2025
Merged

Conversation

dakshpokar
Copy link
Contributor

@dakshpokar dakshpokar commented Mar 15, 2025

Description

Note: This doesn't support Seaborn's FacetGrid construction of the plot yet.

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 base branch from main to feat/multipanel March 15, 2025 05:27
@jooyoungseo jooyoungseo requested a review from Copilot March 15, 2025 14:05
Copy link
Contributor

@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 support for facet plots in py-maidr using the maidr-ts engine and adds several example scripts demonstrating facet plotting with both matplotlib and seaborn. Key changes include:

  • New example scripts for facet plotting with matplotlib and seaborn, including combined bar and line plots.
  • Updates to extractor mixins and plotting modules to improve shared label extraction and data processing for bar and line plots.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
example/facet-subplots/matplotlib/example_mpl_facet_bar_plot.py Adds an example of a matplotlib facet bar plot
example/facet-subplots/seaborn/example_sns_facet_combined_plot.py Adds an example of a combined seaborn facet plot for sales and profit trends
example/facet-subplots/seaborn/example_sns_facet_bar_plot.py Implements a simple facet bar plot example using seaborn
example/facet-subplots/matplotlib/example_mpl_facet_combined_plot.py Adds a matplotlib example combining line and bar plots in facets
maidr/util/mixin/extractor_mixin.py Enhances tick label extraction by adding a fallback for shared x-axes
maidr/core/plot/barplot.py Adjusts handling of bar container data and label mismatches
maidr/core/plot/maidr_plot.py Introduces shared xlabel extraction to improve axis labeling consistency
maidr/core/plot/lineplot.py Filters out default line labels for clearer plot annotations
Comments suppressed due to low confidence (2)

maidr/core/plot/barplot.py:71

  • The commented-out length check between plot elements and their labels may mask data mismatches. Consider either removing the commented code entirely if it is no longer needed or refining the check to ensure that the number of patches always aligns with the extracted labels.
if len(plot) != len(level):

maidr/core/plot/lineplot.py:96

  • Using the hardcoded string "_child0" as a filter for default labels is brittle. Consider extracting this magic string into a well-named constant to improve maintainability and clarity.
line.get_label() if line.get_label() != "_child0" else ""

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 Let's merge this PR once you implement seaborn support and its example.

@dakshpokar
Copy link
Contributor Author

Sure Professor @jooyoungseo!

Base automatically changed from feat/multipanel to main March 18, 2025 21:39
@jooyoungseo jooyoungseo requested a review from Copilot April 21, 2025 13:12
Copy link
Contributor

@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 support for facet plots in py-maidr using maidr-ts and adds several new methods to handle shared axis label extraction across different plot types. Key changes include:

  • Adding a static method to extract shared x tick labels in mixin classes.
  • Creating a new method to extract a shared xlabel and updating axis data extraction in maidr_plot.
  • Updating label extraction in the lineplot and barplot to better handle special cases, and adding several new example scripts for seaborn and matplotlib facet plots.

Reviewed Changes

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

Show a summary per file
File Description
maidr/util/mixin/extractor_mixin.py Added fallback to extract shared xtick labels when level is empty.
maidr/core/plot/maidr_plot.py Introduced extract_shared_xlabel and updated axis data extraction with a default "X" label.
maidr/core/plot/lineplot.py Updated label extraction to ignore placeholder labels in line plots.
maidr/core/plot/barplot.py Modified level extraction to assign empty strings when no labels are found and commented out a length mismatch check.
example/facet-subplots/seaborn/* Added new example scripts demonstrating facet plot implementations using seaborn.
example/facet-subplots/matplotlib/* Added new example scripts demonstrating facet plot implementations using matplotlib.

Comment on lines 87 to +93
def _extract_axes_data(self) -> dict:
"""Extract the plot's axes data"""
return {MaidrKey.X: self.ax.get_xlabel(), MaidrKey.Y: self.ax.get_ylabel()}
x_labels = self.ax.get_xlabel()
if not x_labels:
x_labels = self.extract_shared_xlabel(self.ax)
if not x_labels:
x_labels = "X"
Copy link
Preview

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

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

Defaulting the xlabel to 'X' when no label is found might lead to misleading or unintended axis labeling. It may be beneficial to parameterize this default or add documentation explaining the rationale.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"X" is just the “last‐resort” label and only shows up if no X‑axis label can be found anywhere in your figure or shared group.

@dakshpokar
Copy link
Contributor Author

Professor @jooyoungseo, this PR is ready for merge!

@dakshpokar dakshpokar merged commit d6d6b9a into main Apr 29, 2025
3 checks passed
@dakshpokar dakshpokar deleted the feat/facet-plot branch April 29, 2025 20:22
krishnanand5 pushed a commit to krishnanand5/py_maidr that referenced this pull request May 1, 2025
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