Skip to content
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

Addition of new functionalities for formatting the Cartopy.gridliner ticklabels #1699

Closed
wants to merge 25 commits into from

Conversation

PhilipeRLeal
Copy link

@PhilipeRLeal PhilipeRLeal commented Dec 22, 2020

Dear all,

I would like to make a pull request in cartopy in order to add a new set of functionalities for cartopy's gridline.

The new functionalities encompass small functions that allow any given user to easily format the gridline ticklabel settings (i.e.: decimal separator symbol, hemisphere symbology, etc.).

Rationale

These new assets have been derived from my personal struggle with cartopy's geoaxes and the continuous migration from the past basemap towards cartopy.

In this new branch, the geoaxes class has gained new assets for ticklabel formatting.

This background of this pull request is presented in a comment from the stackoverflow (see here). At the current time, cartopy only supports a fixed set of geographical units for the xticklabels and yticklabels (i.e.: "W" for west coordinates, "E" for east coordinates, "S" for south coordinates, "N" for north coordinates), with no easy way to change them to a user's defined version. Also, there is no easy way to convert the decimal symbol of the coordinates (i.e.: dot "."). For users like me who come from Latin countries, there is a great demand for latin symbols, therefore, instead of using [W,E,S,N and dot"."], one should use the following respectively [O, L, S, N and ","].

Here is a relation of the provided symbols:

O (from Oeste) == West
L (from Leste) == East
N (from Norte) == North
S (from Sul) == South
'.' == ','

I state here that all prior symbols [W,E,S,N and dot"."] have been kept as they were (in international format). Therefore, no changes have been made to the common cartopy's gridline usage. This new Pull request only allows the user to easily change those symbols into any user's defined string/symbol.

---------------------------------------------------------------------------------------------------------------

The list of the new functionalities related to gridline ticklabel settings:

  1. addition of a method for easy setting the decimal separators from the gridline ticklabels (i.e.: dot '.' to comma ',')
  2. addition of a method for easy setting the maximum number of ticks in the gridline
  3. addition of a method for easy setting the hemispheric labels (i.e.: 'N', 'S', 'W' and 'E') to any other provided strings (i.e.: 'Norte', 'Sul', 'Leste', 'Oeste')

Observation:

This is a subdivision of the prior pull request #1693.

In accordance to GregLucas, the former pull request was subdivided into small ones, being this respective pull request solely regarding the gridline ticklabel settings

Check pull request #1698 for the scalebar asset.

Usage example:

import cartopy.crs as ccrs
import cartopy.feature as cfeature

import matplotlib.pyplot as plt


def main():

    plt.figure(figsize=(7, 3))
    ax = plt.axes(projection=ccrs.PlateCarree())
    ax.set_extent([-65, -40, -15, 10])

    # Create a feature for States/Admin 1 regions at 1:50m from Natural Earth
    states_provinces = cfeature.NaturalEarthFeature(
        category='cultural',
        name='admin_1_states_provinces_lines',
        scale='50m',
        facecolor='none')
    ax.add_feature(states_provinces, edgecolor='gray')

    ax.coastlines(resolution='110m')
    ax.coastlines(resolution='110m')
    gl = ax.gridlines(draw_labels=True)

    gl.change_gridline_tick_decimal_separator('{0:.3f}',
                                              axis='both')

    gl.set_latitude_hemisphere_str('Norte', 'Sul')

    gl.set_longitude_hemisphere_str('O', 'L')

    gl.top_labels = False
    gl.right_labels = False
    plt.show()

    return plt.gcf().get_axes(), gl

Implications

None

adrien-berchet and others added 21 commits December 22, 2020 15:38
…onalities here provided. The prior developers branch had several commits which were aggregated into

this single 1st commit.

Add a warning and comments

This is the commit that antecedes all added new commits in respect to the pull request number SciTools#1693 from: SciTools#1693
… setting the number of ticks, and changing the decimal separators in the ticklabels
…ER. Now, the user can directly change the hemispheres (north-south and west-east) ticklabels ('N', 'S', 'W', 'E') from the gridliner instance. Also, new functionalities have been added to the gridliner
…calebar has been updated. Now, the fancy_scalebar has a proper documentation. Also, the geoaxes can directly create a scalebar
…ht added, following the cartopy contributors' standard'
…ive examples and tests. \n The changes here applied allow an easy assess and respective setting of the geoaxes.griline's ticklabels. The settings that can now be changed by the user are the following: \n a) the decimal separator (from dot '.' to any other string (i.e. from dot to comma ','); \n b) the number of decimal places after the coordinate (i.e.: {0:3f}); \n c) the labels of the east-west hemispheres ('W', 'E') - to any other set of labels (i.e.: 'Oeste', 'Leste'); \n d) the labels of the north-south hemispheres ('N', 'S') - to any other set of labels (i.e.: 'Norte', 'Sul'>.
@SciTools-assistant SciTools-assistant added the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Dec 22, 2020
@PhilipeRLeal PhilipeRLeal changed the title Addition of new functionalities for Cartopy.gridliner Addition of new functionalities for formatting the Cartopy.gridliner ticklabels Dec 22, 2020
…for better follow up. Furthermore, the new figure tests have the ImageTesting decorator in its functions.
@SciTools-assistant SciTools-assistant removed the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Dec 27, 2020
@PhilipeRLeal
Copy link
Author

Dear all,

I am wondering when one should close a Pull Request.

In this case, given this pull request (PR) changes, the discussed issue is formally solved. Nevertheless, if this PR is not merged into the main branch of cartopy (i.e.: in the next cartopy's release), the issue will remain present.

I thank you for your time,

@PhilipeRLeal PhilipeRLeal deleted the gridline_ticklabel branch February 3, 2021 19:03
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.

3 participants