cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

Scalebar

Open PhilipeRLeal opened this issue 4 years ago • 9 comments

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 avatar Feb 03 '21 20:02 PhilipeRLeal

Dear developers, now that the scalebar Issue is basically solved, should I close this Issue?

Sincerely,

PhilipeRLeal avatar Feb 07 '21 05:02 PhilipeRLeal

Your code isn't merged in yet, so don't close any of the issues yet. If you put "closes #XX" with a link to the issue you want to close in your PR request it will automatically close the linked issues when someone merges the PR.

greglucas avatar Feb 11 '21 04:02 greglucas

Dear @greglucas, thank you for the information. I have updated the body of this Pull Request adding the term: "closes #490". Therefore, I believe that once this Pull Request is merged, the Issue 490 will then be closed. Corret?

Sincerely,

PhilipeRLeal avatar Feb 11 '21 14:02 PhilipeRLeal

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 avatar Aug 23 '21 08:08 QuLogic

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.

PhilipeRLeal avatar Sep 15 '21 20:09 PhilipeRLeal

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

scollis avatar Jan 26 '22 23:01 scollis

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,

PhilipeRLeal avatar Jan 27 '22 14:01 PhilipeRLeal

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!

drewskoots avatar Feb 08 '23 19:02 drewskoots

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.

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

CLAassistant avatar Apr 08 '24 16:04 CLAassistant