Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Apply standard plot formatting on draw_contours#8332

Draft
bhavyaKhatri2703 wants to merge 4 commits into
sunpy:mainfrom
bhavyaKhatri2703:fix/draw_contours-annotate
Draft

Apply standard plot formatting on draw_contours#8332
bhavyaKhatri2703 wants to merge 4 commits into
sunpy:mainfrom
bhavyaKhatri2703:fix/draw_contours-annotate

Conversation

@bhavyaKhatri2703
Copy link
Copy Markdown

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

@nabobalis nabobalis requested a review from ayshih August 27, 2025 20:30
Comment thread sunpy/map/mapbase.py Outdated
axis_labels_from_ctype(self.coordinate_system[1], self.spatial_units[1])
)
axes.set_title(title)
axes.set_aspect("equal", adjustable="datalim")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How does this look for non-equal data?

Comment thread sunpy/map/mapbase.py Outdated
Comment on lines +2615 to +2618
annotate : `bool` , optional
-If `True` , apply standard map formatting
title : `str`
Title of the contour map.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to add these?

Could we not check if there is an existing axis and if not, label it automatically? Also with the title, that can be set after the plot has been created, I don't know if I see the need for that as a new keyword input.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes we can do that. Remove annotate and title parameters , and apply labels if no existing axes are provided.
pls let me know if i should make those changes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we not check if there is an existing axis and if not, label it automatically?

An existing axis can need to be formatted as well. For example, creating multiple subplots in a figure means that each axis already exists, but is unformatted.

The alternative to a control keyword would be to do some form of automatic detection to distinguish between a base plotting and an overlay plotting. That is, check the existing title and axis labels to see if they appear to be unformatted...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do not need a title keyword argument at all. annotate=True should set the standard title derived from the map.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The alternative to a control keyword would be to do some form of automatic detection to distinguish between a base plotting and an overlay plotting.

Hmm, we actually ought to do something like this for plot() as well...

@nabobalis
Copy link
Copy Markdown
Member

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.

@ayshih
Copy link
Copy Markdown
Member

ayshih commented Aug 28, 2025

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.

@bhavyaKhatri2703
Copy link
Copy Markdown
Author

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.

@ayshih
Copy link
Copy Markdown
Member

ayshih commented Aug 28, 2025

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.

@bhavyaKhatri2703 bhavyaKhatri2703 force-pushed the fix/draw_contours-annotate branch from 205c313 to 8c3db2f Compare August 28, 2025 18:06
@bhavyaKhatri2703
Copy link
Copy Markdown
Author

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?

@ayshih
Copy link
Copy Markdown
Member

ayshih commented Sep 2, 2025

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.

@bhavyaKhatri2703
Copy link
Copy Markdown
Author

@ayshih can u please review this pr now?

@nabobalis
Copy link
Copy Markdown
Member

@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.

Copy link
Copy Markdown
Member

@ayshih ayshih left a comment

Choose a reason for hiding this comment

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

You're on the right track, but you need to change the parametrized figure test because you aren't actually testing the various methods as intended.

You also need to add a changelog entry.

aia171_test_map.peek(draw_grid=True)



Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change

Revert this spurious newline

def test_auto_format_plot_methods(aia171_test_map, method, kwargs):
fig = Figure()
ax = fig.add_subplot(projection=aia171_test_map)
aia171_test_map.plot(axes=ax)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
aia171_test_map.plot(axes=ax)

You need to take this line out, because as written you are testing the autoformatting of only plot() because that is the first method called

Comment on lines +93 to +98
}
} No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert this change

@ayshih ayshih added map Affects the map submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers) labels Sep 17, 2025
@bhavyaKhatri2703
Copy link
Copy Markdown
Author

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()"

@nabobalis
Copy link
Copy Markdown
Member

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

@Cadair Cadair marked this pull request as draft October 29, 2025 13:01
@github-actions
Copy link
Copy Markdown
Contributor

Hello 👋, Thanks for your contribution to sunpy!
I have marked this pull request as stale because there hasn't had any activity in five months. If you are still working on this, or if it's waiting on a maintainer to look at it then please let us know and we will keep it open. Please add a comment with: @sunpy/sunpy-developers to get someone's attention.
If nobody comments on this pull request for another month, it will be closed.

@github-actions github-actions Bot added the Stale The bot will close this PR after 6 months (if enabled on this repo). label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

map Affects the map submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers) Stale The bot will close this PR after 6 months (if enabled on this repo).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Map.draw_contours() does not apply our standard plot formatting

3 participants