sunpy icon indicating copy to clipboard operation
sunpy copied to clipboard

Apply standard plot formatting on draw_contours

Open bhavyaKhatri2703 opened this issue 4 months ago • 10 comments

PR Description

This PR fixes the lack of standard plot formatting in GenericMap.draw_contours().

Adds an annotate keyword (default True) and Title field to draw_contours() so that axis labels, titles, and aspect ratio are applied consistently, similar to plot().

Figure_1

Fixes #8331

bhavyaKhatri2703 avatar Aug 27 '25 19:08 bhavyaKhatri2703

Thanks for the PR @bhavyaKhatri2703, I have asked Albert to take a deeper look into the PR.

For now I just have a few comments and the need for us to add a few test cases to ensure this is working as intended. See https://docs.sunpy.org/en/latest/dev_guide/contents/tests.html#figure-unit-tests for some guidance on how to add them.

If you get stuck, please do ask.

nabobalis avatar Aug 27 '25 21:08 nabobalis

Thanks for creating this PR! Some of your code has issues, but it's moot because I think we should implement the better handling of formatting I suggested above. Here's a branch showing my draft implementation: https://github.com/sunpy/sunpy/compare/main...ayshih:sunpy:plot_formatting

Let me know if you want to incorporate my code changes into your PR – and then you can do the important stuff of adding corresponding figure tests – or if you instead want me to take over your PR.

ayshih avatar Aug 28 '25 14:08 ayshih

Thanks for creating this PR! Some of your code has issues, but it's moot because I think we should implement the better handling of formatting I suggested above. Here's a branch showing my draft implementation: main...ayshih:sunpy:plot_formatting

Let me know if you want to incorporate my code changes into your PR – and then you can do the important stuff of adding corresponding figure tests – or if you instead want me to take over your PR.

Thanks for reviewing my PR! Can i merge your changes into my branch? and I'll try to work on adding the figure tests.

bhavyaKhatri2703 avatar Aug 28 '25 15:08 bhavyaKhatri2703

Can i merge your changes into my branch? and I'll try to work on adding the figure tests.

Yes, please go ahead!

I did not do anything about the aspect ratio. Upon further thought, it may not make sense to impose a default aspect ratio for draw_* methods, so I think that should be deferred to a potential future PR.

ayshih avatar Aug 28 '25 17:08 ayshih

Can i merge your changes into my branch? and I'll try to work on adding the figure tests.

Yes, please go ahead!

I did not do anything about the aspect ratio. Upon further thought, it may not make sense to impose a default aspect ratio for draw_* methods, so I think that should be deferred to a potential future PR.

just a question do I need to add test functions for every draw_* function for checking auto formatting?

bhavyaKhatri2703 avatar Aug 28 '25 19:08 bhavyaKhatri2703

Rather than writing a separate figure test for each method, you can probably set it up as a parametrized figure test, where the values for the parameter are the methods to be tested.

ayshih avatar Sep 02 '25 14:09 ayshih

@ayshih can u please review this pr now?

bhavyaKhatri2703 avatar Sep 08 '25 07:09 bhavyaKhatri2703

@ayshih can u please review this pr now?

Please do not @ people for reviews. Albert is aware of this PR and will review it when he gets a chance.

nabobalis avatar Sep 08 '25 15:09 nabobalis

so i am struggling with passing the test for the draw_grid method it keeps giving me the warning :

"The conversion of these 2D helioprojective coordinates to 3D is all NaNs because off-disk coordinates need an additional assumption to be mapped to calculate distance from the observer. Consider using the context manager SphericalScreen()"

bhavyaKhatri2703 avatar Sep 27 '25 09:09 bhavyaKhatri2703

I am not sure if https://docs.sunpy.org/en/stable/generated/gallery/plotting/offdisk_contours.html will be helpful reading.

nabobalis avatar Sep 27 '25 17:09 nabobalis