Apply standard plot formatting on draw_contours#8332
Conversation
| axis_labels_from_ctype(self.coordinate_system[1], self.spatial_units[1]) | ||
| ) | ||
| axes.set_title(title) | ||
| axes.set_aspect("equal", adjustable="datalim") |
There was a problem hiding this comment.
How does this look for non-equal data?
| annotate : `bool` , optional | ||
| -If `True` , apply standard map formatting | ||
| title : `str` | ||
| Title of the contour map. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
We do not need a title keyword argument at all. annotate=True should set the standard title derived from the map.
There was a problem hiding this comment.
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...
|
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. |
|
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. |
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 |
205c313 to
8c3db2f
Compare
just a question do I need to add test functions for every draw_* function for checking auto formatting? |
|
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 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. |
ayshih
left a comment
There was a problem hiding this comment.
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) | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
| 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
| } | ||
| } No newline at end of file |
|
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 |
|
I am not sure if https://docs.sunpy.org/en/stable/generated/gallery/plotting/offdisk_contours.html will be helpful reading. |
|
Hello 👋, Thanks for your contribution to sunpy! |
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().
Fixes #8331