Skip to content

Adds Bayesian plots to Python#52

Merged
alexhroom merged 25 commits intoRascalSoftware:mainfrom
alexhroom:45-additional-plots
Aug 7, 2024
Merged

Adds Bayesian plots to Python#52
alexhroom merged 25 commits intoRascalSoftware:mainfrom
alexhroom:45-additional-plots

Conversation

@alexhroom
Copy link
Collaborator

@alexhroom alexhroom commented Jul 24, 2024

This PR fixes #45 by adding the remaining plotting functionality from RAT to the Python API. These are:

  • cornerPlot -> plot_corner
  • plotHists -> plot_hists
  • bayesShadedPlot -> new bayes parameter for plot_ref_sld
  • histp -> plot_one_hist (with estimated_density parameter for estimated density overplot)
  • mcmcplot -> plot_chain
  • plotBayes -> plot_bayes (just calls plot_ref_sld with and without confidence intervals, plot_hists and plot_corner)

@alexhroom alexhroom requested a review from DrPaulSharp July 24, 2024 08:10
@alexhroom alexhroom marked this pull request as ready for review July 24, 2024 09:53
Copy link
Collaborator

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

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

The plots are looking good so far, and I'm really pleased you've thought at each stage how to make them look as good as possible and add extra features.

There are two main jobs for you to do: add tests and address the issue with normalisation (corner is not playing ball unfortunately).

Have a look through the other comments too, hopefully there's some ideas there that will turn the plots up to 11.

Copy link
Collaborator

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

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

The plots are looking in great shape and the tests look good. I have a few more specific comments, plus a few more general things to think about to make this module as strong as possible:

  • I think we need to consider the naming convention of plotting routines. I think rather than e.g., "plot_hist" and "plot_hist_panel" we should have "plot_one_hist" and "plot_hists" (of course "plot_hists" and similar can plot a single example with one parameter index provided). This better matches the matlab and gives the simpler name to the more commonly used routines.
  • Please add a test for plot_ref_sld with shading
  • When running test_plotting I get the warning
RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). Consider using `matplotlib.pyplot.close()`

I'd suggest explicitly closing figures generated by the tests, hopefully they will run quicker too. Also consider patching routines that generate figures if the actual figures are not required.

I'll try and establish what's happening with the live plots and matplotlib errors that we discussed.

@alexhroom alexhroom requested a review from DrPaulSharp August 1, 2024 13:37
Copy link
Collaborator

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

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

I've a few specific comments, alongside those could you please review the test coverage - it's lacking in a couple of places, in particular estimated densities on histograms and bad input for indices on plots.

@alexhroom alexhroom requested a review from DrPaulSharp August 6, 2024 12:42
Copy link
Collaborator

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

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

Have a look at the final point on tidying up the estimated density code and then we're all done!

if estimated_density is not None:
if isinstance(estimated_density, str):
estimated_density = {"default": estimated_density}
default = estimated_density.get("default")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make more sense to write:

if isinstance(estimated_density, str):
    default = estimated_density
else:
    default = estimated_density.pop("default")

and remove lines 716-717.

I think this is a little clearer and avoids making and then emptying the estimated_density dict.

Copy link
Collaborator Author

@alexhroom alexhroom Aug 6, 2024

Choose a reason for hiding this comment

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

can't do this because you iterate over estimated_density.items() so it must be a dict by that line. although looking at it i'm becoming dissatisfied with how the loop looks generally. will try to come up with a neater way

@alexhroom alexhroom merged commit 05acde5 into RascalSoftware:main Aug 7, 2024
@alexhroom alexhroom deleted the 45-additional-plots branch August 7, 2024 08:53
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.

Add additional plots

2 participants