-
Notifications
You must be signed in to change notification settings - Fork 365
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
Labels visibility from side spines (fix #1530) #1537
Conversation
@QuLogic Does this fit with getting 0.18 out the door? |
I think bug fixes should be okay. |
This could use a test though; doesn't have to be an image test, just a check that the expected labels are set visible. |
I'll add a test tomorrow. |
Do not include |
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 cannot go into 0.18 with all the removals from master
. I'm also not super keen on adding new functionality after the rc, especially without tests.
@QuLogic I agree with you. This is more for 0.19. |
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 seems quite complicated for a beginner to think about now with all the label options. A nice example showing all of these gridliner uses and why someone may be interested in them might be nice. Before it was just True/False, now it can be boolean, string, list, or dict in addition?
boolean: whether or not to draw labels
string of x/y: will only draw labels of the given CRS coordinate string, but draw them on any side?
list: will draw any x/y CRS labels, but only on the input sides?
dictionary: can define x/y for any side.
I also wonder if this may be adding too many options to do the same thing in multiple places. Do we want to limit the number of options for this at all?
There are really only 8 total options {x, y}{top, bottom, left, right} I think? So, maybe we should bring all of those attributes back from their deprecation that I did previously since you're implementing that capability here. I guess my preference would be to drop the dictionary and string options and then the list could have top_x
or top_labels_x
or something similar as input to decide what to draw (probably try to make it exactly the same as the attribute access?). I think being explicit with only a few options will be easier to explain and maintain.
Okay. I just wrote example of use for better reasoning.
In the incoming PR that fixes #1541, I had this support:
In all case, we must make sure that the user can control everything. If aliases are used as you suggest, here is the list (whatever the format): The current gallery example that is dedicated to the gridliner can be extended make it to clearer to the users. |
I'm still getting hung up on all of the various ways that one can request the labels to be drawn with these changes and just thought of a question. Why do we have The name |
My contribution goal on this aspect is to make the user be able to decide the details, while keeping the current API. However, we must be careful on a few points:
|
I agree with your assessment of not breaking the backwards API, which is why I'm hesitant to add the dictionary functionality because it would make things even trickier to change in the future. Currently we only allow True/False for the Gridliner, so you're adding two more cases, a list and a dict as input, which just seems like too many ways to allow for input. (I am advocating to keep the list functionality below though) For a gridliner, the x/y are always in reference to its own coordinate system and not the "axes" projection I thought? Isn't that why the ['top', 'bottom', 'left', 'right'] come in to distinguish the axes projection sides. What I'd propose is to add Another options is to not add in any new options in |
That's probably the best solution because
It may be interesting to ask the opinion of other people to confirm these choices before coding them. @dopplershift @QuLogic @lukelbd ? |
A few figures that were made with the last commit : https://drive.google.com/drive/folders/15Sz5buIrjPcEz1FwniLgBDYn6GCXvNV7?usp=sharing |
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.
When going through the images you posted I noticed a few things that may be worth looking into:
- The Geostationary and Nearside projection rotated labels (
gridlines
) are at an angle and not horizontal - The RotatedPole labels are inside the projection even though
inside=False
inside=True
,zoom=True
the InterruptedGoode projection has a label that projects outside of the bounds- Some of the labels on the top/bottom artists go opposite directions. On the Mercator image of
zoom=True
,rotate=gridlines
the top label directions are 180 degrees flipped compared to the bottom labels.
There are a lot of lists of artists that you're carrying around here just to see which side/coordinate it belongs to. I'm wondering if you can abstract that information out to a LabelArtist()
class that would contain the information of where it is, what side it belongs to, and be able to calculate intersections of itself and the boundary, etc... (Not saying you have to do this)
For your comment about uploading image comparison tests: I personally think we should get rid of the massive images with all of the projections and just choose a few of the representative projections to test. Every time a little update/position change occurs we either have to change the tolerance or update a 1 MB file in the repo and they are pretty fickle with alignments/positioning too. Maybe move the current test images to an Example instead?
@greglucas here are a few answers. Gridlines are not parallel in the GeoStationary and Nearside projections, and even less near the map boundary, as you can see on the following figure. A solution would be to take more points to estimate the gridline angle. Ok for the opposite direction of labels. I'll try to find a solution. Let see later for other problems. |
I think all labels that are inside the map boundary with inside=False are inline labels. |
@stefraynaud, I apologize for losing track of this PR. Are there other changes you were going to make on this PR? If you can add any other changes and rebase I'll take a look at it again. |
31ae25c
to
c2d021e
Compare
c2d021e
to
f2191fc
Compare
Should I add an entry to the contributors? |
f2191fc
to
d276da0
Compare
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.
There are still a few documentation wordsmith suggestions I had, but other than that I think this is good to go.
d276da0
to
b9047ae
Compare
It now takes into account the side label visibility in the rotation of labels. Add better and more control to gridliner labels drawing * draw_labels accepts more than a boolean. * label positioning is better estimates thanks to side spines Clean gridliner Improve the rotation and visibility of gridline labels - the location of labels takes spines into account - lines and labels are redrawn when zooming - the rotation of labels is both more tunable and strict - added the inside parameter for drawing labels inside the the boundary Fix stickler Fix padding Fix the rotation of labels Possible values: True, False, None None: it depends on the projection. True: rotate along gridlines. False: horizontal. Another type of location for labels in addition to left, right, top and bottom: geo. By the way, add more control to the gridliner init by adding the xpadding and ypadding keywords. Add support for float values of rotate_labels Also expose xlabel_style, ylabel_style and labels_bbox_style as keyword argument to gridlines() and Gridliner(). Note that labels_bbox_style no longer override the bbox value if x/ylabel_style. Fix alignments Fix labels in classic mode Fix gridliner labels Add Label class Fix _get_loc_from_spine_intersection Fix case where gridline stop before map boundary Update of the baseline images Fix linter Fix gridliner Fix gridliner compat with old mpl Fix artist.update call Fix labels drawing Add more help for draw_labels fix linting Add myself to contributors Fix docstrings Fix linting
b9047ae
to
3f9c365
Compare
I found the suggestions I missed. They are resolved now. |
Out of curiousity @greglucas, will this fix be pushed to the 0.19 release (e.g. 0.19.1) or included in 0.20? Very much looking forward to these changes, which I believe will make a big difference in allowing Cartopy to produce publication-ready figures out of the box. |
This changes some API, so it will be v0.20. @QuLogic, you have some changes requested on this. Mind taking another look? |
This is going into a fresh 0.20 now. The block was for changes not to go into the 0.18 RC a while ago.
Will give it a few more days here in case anyone wants to comment. I still think this is a significant improvement over our current state of things with the gridliner. |
Yes. Anyway, there will always be time to make improvements before the next release, just in case. |
@stefraynaud, thank you for your patience on this PR!! (and effort in keeping it moving) |
@greglucas Don't worry. I'm really happy that we took time to achieve this result. There are certainly things that can be improved, but I think we did things carefuly, taking all opinions into account, which was not easy. Good to colaborate with you! |
res = {} | ||
for loc in 'left', 'right', 'top', 'bottom': | ||
artists = getattr(gl, loc+'_label_artists') | ||
res[loc] = [a.get_text() for a in artists if a.get_visible()] |
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 test is broken; it doesn't compare res
with result
, and now (or maybe even since the beginning) res
doesn't match what you've put as expected.
why does it be fixed in version 0.20? the rotation of labels can not be set. |
Rationale
It now takes into account the side label visibility in the rotation of labels.
Implications
Closes #1530 #1541 #1559 #1560 #1576 #1642 #1666 #1722 #1758