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

Scalebar #1728

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open

Scalebar #1728

wants to merge 67 commits into from

Conversation

PhilipeRLeal
Copy link

@PhilipeRLeal PhilipeRLeal commented Feb 3, 2021

Issue #490

This Pull Requests closes #490

Rationale

In respect to the discussed in #490, here is an implementation of a scalebar for geoaxes.

The algorithm allows one to import the scalebar function directly from cartopy, or be directly called from the Goeaxes.

Implications

None applicable

Limitations:

So far, I have only been capable of inserting the scalebar without a background.

Here is an example for using it:


geoaxes plots with respective scalebar  for multiple projections

TODO:

Add some background for the scalebar

Code for generating the above examples:


import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.mpl.scalebar import fancy_scalebar


def test_scalebar():
    """Test the scalebar"""

    fig, axes = plt.subplots(1, 2,
                             subplot_kw={'projection':
                                         ccrs.Mercator()})

    projections = [ccrs.Mercator(), ccrs.PlateCarree()]

    axes = axes.ravel()
    try:
        for proj, ax in zip(projections, axes):
            ax.projection = proj
            fancy_scalebar(ax,
                           location=(0.5, 0.2),
                           length=1000_000,
                           unit_name='km',
                           max_stripes=5,
                           fontsize=8,
                           dy=0.05)

            ax.gridlines(draw_labels=True)
            ax.stock_img()
            ax.coastlines()
        condition = True
    except BaseException as err:
        print(err)
        condition = False

    assert(condition)


def test_scalebar_within_geoaxes():
    """Test scalebat within the geoaxes"""

    fig, axes = plt.subplots(1, 2,
                             subplot_kw={'projection':
                                         ccrs.Mercator()})

    projections = [ccrs.Mercator(),
                   ccrs.PlateCarree()]

    axes = axes.ravel()
    try:
        for proj, ax in zip(projections, axes):
            ax.projection = proj

            ax.set_extent([-60, -35, -40, 10])
            ax.gridlines(draw_labels=True)
            ax.add_scalebar(location=(0.5, 0.5),
                            length=250_000,
                            dy=5,
                            max_stripes=3)
            ax.stock_img()
            ax.coastlines()

        condition = True
    except BaseException as err:
        print(err)
        condition = False

    assert(condition)


if '__main__' == __name__:
    test_scalebar()
    test_scalebar_within_geoaxes()

PhilipeRLeal and others added 30 commits December 22, 2020 14:48
…cartopy's original master branch has been updated by the addition of the scalebar method in the geoaxes. A test and an example files of the scalebar method are also provided
…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'>.
…for better follow up. Furthermore, the new figure tests have the ImageTesting decorator in its functions.
…offset subclasses. TODO: there is still some problems regarding how to add the ticklabels into the scalebar's ticklabels...
description of the add_scalebar function was updated.
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/scalebar.py Outdated Show resolved Hide resolved
@theroggy theroggy mentioned this pull request Jun 10, 2021
@QuLogic
Copy link
Member

QuLogic commented Aug 23, 2021

Running PEP8 (or whatever formatter you used) on everything is very confusing, as it muddles what it is you actually changed here. You also seem to have mixed in your other PR here, so I really don't know what to look at.

numpy array's base method has been deleted within the "_point_along_line" function
numpy "base" method was dropped from the geodesic.inverse results.
Typo solved from the TextArea
The Old "AttributeError: module 'cartopy.crs' has no attribute 'PROJ4_VERSION'
_________________ ERROR collecting tests/mpl/test_scalebar.py _________________
" has been solved in this Commit
Spacing error solved
typo solved
minimumdescent=True is now deprecated within matplotlib
Copied from the cartopy's master branch
It is now exactly equal to cartopy's master branch
@PhilipeRLeal
Copy link
Author

Running PEP8 (or whatever formatter you used) on everything is very confusing, as it muddles what it is you actually changed here. You also seem to have mixed in your other PR here, so I really don't know what to look at.

@QuLogic, I have tried to clean all this confusion into this new commit. See if it helps.

@scollis
Copy link

scollis commented Jan 26, 2022

Just want to add this is exactly the feature I am looking for! Need any help getting this merged?

@PhilipeRLeal
Copy link
Author

Just want to add this is exactly the feature I am looking for! Need any help getting this merged?

Yes, please. I have done all I could do to facilitate the merge. Nevertheless, the time I updated this Pull Request, there were several LINT errors that would not allow a Merge. Therefore, I had to fix them all (even the ones that were not caused by this branch). As a consequence, it seems that this branch commit's history is now denser than the reviewers expected.

Let me know if I can be of any service.

Sincerely,

@drewskoots
Copy link

Any update on the progress with this? If not, is there something a complete beginner to this particular toolbox could do to move it along? Would love to see this feature implemented!

@CLAassistant
Copy link

CLAassistant commented Apr 8, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ PhilipeRLeal
❌ adrien-berchet
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Scale bar
8 participants