-
Notifications
You must be signed in to change notification settings - Fork 196
Refactor Plotting functions #1631
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
base: main
Are you sure you want to change the base?
Conversation
…otting function arguments
…or to mpl kwargs by default
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1631 +/- ##
=======================================
Coverage ? 82.70%
=======================================
Files ? 136
Lines ? 11256
Branches ? 0
=======================================
Hits ? 9309
Misses ? 1947
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more.
|
sbi/analysis/plot.py
Outdated
| elif isinstance(fig_kwargs, FigKwargs): | ||
| fig_kwargs = asdict(fig_kwargs) | ||
| else: | ||
| fig_kwargs = update(asdict(FigKwargs()), fig_kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has almost no guarantee that valid kwargs come out.
asdict(replace(FigKwargs(), **fig_kwargs))
Would mean that the options from the user passed kwargs correspond to a field in FigKwargs and I think it would also run the any init or post init method that might do additional validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even easier: asdict(FigKwargs(**fig_kwargs))
sbi/analysis/plot.py
Outdated
| the number of samples when a legend is specified. | ||
|
|
||
| Returns: | ||
| A dictionary of fully resolved figure-level keyword arguments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you choose to convert all possible ways of specifying kwargs to a dict; Why not convert everything to a Dataclass and then convert it to a dict in the last possible moment?
sbi/analysis/plotting_classes.py
Outdated
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class DiagKwargs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the name DiagOptions; Kwargs sounds like a dictionary.
sbi/analysis/plotting_classes.py
Outdated
| class TitleFormat: | ||
| fontsize: int = 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure all the options you have here need to be exposed in sbi? Matplotlib figures are mutable so many things can be changed after the figure is returned to the user. As long as data is plotted correctly and with the right color, most other things (e.g. titles) can be changed afterwards.
This PR refactors the plotting functions by improving code modularity for the
pairplotandmarginal_pairplotfunctions and provides typed configuration using dataclasses. The changes include:KdeDiagOptions,HistDiagOptions,ScatterDiagOptionspassed topairplotandmarginal_pairplotfunctions, for customizing the diagonal plotting regions which are passed to thediag_kwargsargument.KdeOffDiagOptions,HistOffDiagOptions,ScatterOffDiagOptions,ContourOffDiagOptions,PlotOffDiagKwargspassed to thepairplotfunction, for customizing the upper and lower plotting regions, which are passed to theupper_kwargsandlower_kwargsarguments.FigOptionspassed topairplotandmarginal_pairplotfunctions, for customizing the figure which is passed to thefig_kwargsargument.sbi/utils/plotting_helpers.pypairplotandmarginal_pairplotfunctions.docs/advanced_tutorials/17_plotting_functionality.ipynb.This pull request builds upon the idea by @danielmk in PR #1529.