Skip to content

feat: add plot_params dict to plot_pytrendy for customisation#122

Open
gyr0tron wants to merge 2 commits into
developfrom
enhancement/plot_customisation
Open

feat: add plot_params dict to plot_pytrendy for customisation#122
gyr0tron wants to merge 2 commits into
developfrom
enhancement/plot_customisation

Conversation

@gyr0tron
Copy link
Copy Markdown
Collaborator

@gyr0tron gyr0tron commented May 6, 2026

  • Add optional plot_params dict support to plot_pytrendy.py
  • Allows users to customise plot settings such as figsize, title, colours, alpha, grid and legend placement
  • Maintains backward compatibility for existing plot_pytrendy usage as default params are still in place

Changes

  • Updated plot_pytrendy signature to accept plot_params
  • Updated test helper in test_plot_pytrendy_core.py to accept plot_params and added a new test verifying that custom figsize and title work.

Notes

Currently, only a limited set of colours are supported (only the ones supported by matplotlib starting with the keyword 'light'). This could be made into a new issue on its own to dynamically process lighter versions of colours that user specifies for fill and darker versions of respective colours for texts and shapes if the user only specifies a base colour e.g. red, blue, etc.

Issue

Closes #68

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

📚 Docs preview deployed!

Your docs preview is available at: https://russellsb.github.io/pytrendy/pr-122/

This preview will be removed when the PR is closed.

github-actions Bot added a commit that referenced this pull request May 6, 2026
@gyr0tron gyr0tron requested a review from RussellSB May 6, 2026 21:59
github-actions Bot added a commit that referenced this pull request May 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Owner

@RussellSB RussellSB left a comment

Choose a reason for hiding this comment

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

Thanks Simmar. Appreciate you going into way more than just figsize and title. I've left some nitpick comments re the API structure, docstring format for dict, and hard setting legend ncols.

import matplotlib.patches as mpatches

def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict], suppress_show: bool = False) -> plt.Figure:
def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict], suppress_show: bool = False, plot_params: dict = None) -> plt.Figure:
Copy link
Copy Markdown
Owner

@RussellSB RussellSB May 17, 2026

Choose a reason for hiding this comment

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

Can you also define this in the main detect_trends() call? E.g. what was attempted in the stale PR. This way it would be more accessible to the user. The dict plot_params can be passed through the main access point detect_trends, to the internal plot_pytrendy function.

plot_params (dict, optional):
Dictionary of plotting parameters to customise the figure.
Supported keys are 'figsize' (tuple), 'title' (str), 'xlabel' (str), 'ylabel' (str), 'colors' (dict of direction to color), 'alpha' (float), 'grid' (dict), 'legend_loc' (str), 'legend_bbox_to_anchor' (tuple), 'legend_ncol' (int).
Defaults to None (uses internal defaults).
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

can you re-format this docsting to e.g. how method_params was done? It just ends up looking nicer in the API Reference docs, e.g.: https://russellsb.github.io/pytrendy/pr-122/reference/pytrendy/detect_trends/

'grid': {'visible': True, 'which': 'major', 'color': 'gray', 'alpha': 0.3},
'legend_loc': 'upper right',
'legend_bbox_to_anchor': (1, 1.15),
'legend_ncol': 4,
Copy link
Copy Markdown
Owner

@RussellSB RussellSB May 17, 2026

Choose a reason for hiding this comment

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

I dont think legend_ncol should be customisable since Up, Down, Flat, Noise is currently always set to be length 4 for legend_handles . Im not sure what would happen if you set it to e.g. 6 or 2, but I assume it would break.

@RussellSB RussellSB linked an issue May 17, 2026 that may be closed by this pull request
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.

[Enhancement] Make plot pytrendy customisable

2 participants