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

Modularize customization of time series plots #3009

Merged
merged 8 commits into from Oct 10, 2022

Conversation

ryankarlos
Copy link
Contributor

@ryankarlos ryankarlos commented Oct 1, 2022

Related Issue or bug

Closes #2417

Describe the changes you've made

abstract out redundant code into util functions for customising plots which could be reused in multiple plotting methods/functions

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

@ryankarlos ryankarlos changed the title abstract out into function for reuse Modularize customization of time series plots Oct 1, 2022
@ryankarlos
Copy link
Contributor Author

@ngupta23 Will add docstring and test for new util which customises plot. I currently moved this to pycaret/internal/plots/utils/time_series.py but let me know if you prefer it moved to another module.

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Oct 1, 2022

There. are few other cases like below which also update x, y axes and traces , and are duplicated in two to three other plotting methods.

with fig.batch_update():
for i in np.arange(1, ncols + 1):
fig.update_xaxes(title_text="Lags", row=1, col=i)
# Only on first column
fig.update_yaxes(title_text=plot.upper(), row=1, col=1)
template = _resolve_dict_keys(
dict_=fig_kwargs, key="template", defaults=fig_defaults
)
fig.update_layout(title=title, showlegend=False, template=template)
fig.update_traces(marker={"size": 10})
fig = _update_fig_dimensions(
fig=fig, fig_kwargs=fig_kwargs, fig_defaults=fig_defaults
)

Would you prefer if this was all handled within the _plot_fig_update function i created or have another function which calls this for these special cases -- something like below ? I could rename _plot_fig_update to _plot_fig_dim_layout to be
more explicit ..... something like below:

def _plot_update_trace_axes_dim_layout(fig, title, ncols, size, fig_defaults, fig_kwargs, show_legend):
     with fig.batch_update(): 
         for i in np.arange(1, ncols + 1): 
             fig.update_xaxes(title_text="Lags", row=1, col=i) 
  
     # Only on first column 
     fig.update_yaxes(title_text=plot.upper(), row=1, col=1) 
     fig.update_traces(marker={"size": 10}) 

     return  _plot_fig_dim_layout(fig, title, fig_defaults, fig_kwargs, show_legend)

ncols and size could be incorporated into fig_kwargs i guess and fetched from there in the code block if you prefer having fewer arguments

@ryankarlos ryankarlos mentioned this pull request Oct 1, 2022
13 tasks
@ngupta23
Copy link
Collaborator

ngupta23 commented Oct 3, 2022

@ryankarlos Can you check why the tests are failing? Thanks!

@ryankarlos
Copy link
Contributor Author

please see comment in #3010 (comment)

fig = _update_fig_dimensions(
fig=fig, fig_kwargs=fig_kwargs, fig_defaults=fig_defaults
)
fig = _plot_fig_update(fig, title, fig_defaults, fig_kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should show_legend be True here?

Copy link
Collaborator

@ngupta23 ngupta23 left a comment

Choose a reason for hiding this comment

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

Looks good overall. I think there may be a small change needed which I have noted. Please have a look. Thanks!

@ngupta23 ngupta23 added time_series Topics related to the time series plot_model labels Oct 8, 2022
@ngupta23 ngupta23 added this to In progress in Time Series Forecasting via automation Oct 8, 2022
@ngupta23 ngupta23 added this to the pycaret 3.0.0rc5 milestone Oct 8, 2022
@ngupta23
Copy link
Collaborator

ngupta23 commented Oct 8, 2022

There. are few other cases like below which also update x, y axes and traces , and are duplicated in two to three other plotting methods.

I do not think that those are that pervasive, so it is ok to leave it as is for now.

@ryankarlos
Copy link
Contributor Author

Thanks @ngupta23 pushed new changes and merged master

@ngupta23 ngupta23 merged commit 4d24562 into pycaret:master Oct 10, 2022
Time Series Forecasting automation moved this from In progress to Done Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plot_model time_series Topics related to the time series
Development

Successfully merging this pull request may close these issues.

Modularize customization of time series plots
2 participants