question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scale created by drawmapscale seems incorrect

See original GitHub issue

Issue description

Drawing a scale in basemap using ‘drawmapscale’ results in a scale which is not correct. It seems the bar is about 1.6 times to short. So, a scale with the indication 10km above it is actually only about 6.25 km long.

The two attachments show:

  • a basemap plot (code below) for a region around Belgium. Belgium is about 230 km width, when measured due east starting from the most southern point of the coastline. As can be seen, the ruler is to small, it does not go from coast till the eastern border.
  • a screenshot from google earth showing the same area with a measurement, confirming that the country is indeed 230 km wide.

Code which shows the issue:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
map = Basemap(projection='merc', lat_0 = 50, lon_0 = 4,resolution = 'h', area_thresh = 0.1,
llcrnrlon=1.75, llcrnrlat=49.0,urcrnrlon=7, urcrnrlat=52)
map.drawcoastlines()
map.drawcountries()
map.drawmapboundary(fill_color = 'lightblue')
map.fillcontinents(color = 'white',lake_color = 'lightblue')
map.drawmapscale(4.27,51.11,4.5,50.89,228, barstyle='fancy', units='km', labelstyle='simple',\
fillcolor1='w', fillcolor2='#555555', fontcolor='#555555')
plt.show(block=False)

I tried similar plottings in nautical mile, meters, etc, all with the same problem: the ruler shows the correct numbers, but is 1.6x to small. I also tried with much smaller scales (eg 10 km),other barstyle, etc and referenced them to known distances on a map, and the same issue occurs.

Technical info:

Python version: 2.7.6 matplotlib version: 1.3.1 Basemap 1.0.7 + dfsg-1 OS: linux Mint 17 Qiana (64-bit version) Installation method: all packages installed automatically during Mint installation or via Synaptic package manager using the official repository no customization

plot1

plot2

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jenshnielsencommented, Jan 9, 2015

Another work around is to use the Transverse Mercator Projection http://matplotlib.org/basemap/users/tmerc.html

I the Belgium example that seems to return the expected result.

0reactions
lafayssecommented, Mar 18, 2015

For people who want to use that function with a trick to fix this bug: it is possible to modify the labels of the scale. Here is my code to plot a correct scale of length 50 km over French Alps:

   # Map definition
   latmin=43.9
   latmax=46.5
   lonmin=5.2
   lonmax=7.9        

   mymap = Basemap(llcrnrlat=latmin, urcrnrlat=latmax, llcrnrlon=lonmin, urcrnrlon=lonmax, projection="merc", resolution='i', fix_aspect=True)

    # Distance we want to plot
    dref=50

    # Coordinates
    lat0=mymap.llcrnrlat+0.2
    lon0=mymap.llcrnrlon+0.4

    # Tricked distance to provide to the the function 
    distance=dref/np.cos(lat0*np.pi/180.)

    # Due to the bug, the function will draw a bar of length dref
    scale=mymap.drawmapscale(lon0,lat0,lon0,lat0,distance,barstyle='fancy', units='km', labelstyle='simple',fillcolor1='w', fillcolor2='#555555', fontcolor='#555555')        

    # Modify the labels with dref instead of distance
    scale[12].set_text(dref/2)
    scale[13].set_text(dref)
Read more comments on GitHub >

github_iconTop Results From Across the Web

scale created by drawmapscale seems incorrect #3800 - GitHub
Issue description Drawing a scale in basemap using 'drawmapscale' results in a scale which is not correct. It seems the bar is about...
Read more >
Issue with drawmapscale from basemap - Stack Overflow
I set the figure size bigger, then plot, and get a map with better scale bar. from mpl_toolkits.basemap import Basemap import ...
Read more >
Basemap utility functions — Basemap tutorial 0.1 documentation
drawmapscale ¶. Draws the scale of the map at the indicated position. drawmapscale(lon, lat, lon0, lat0, length, barstyle='simple' ...
Read more >
Issue With Drawmapscale From Basemap - ADocLib
Issue description Drawing a scale in basemap using 'drawmapscale' results in a scale which is not correct. It seems the bar is about...
Read more >
Basemap Matplotlib Toolkit 1.2.1 documentation
Default is False (projection coordinates are automatically rotated). ... In order to use this method, the Basemap instance must be created using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found