matplotlib-scalebar icon indicating copy to clipboard operation
matplotlib-scalebar copied to clipboard

How to add a scalebar using matplotlib-scalebar in geemap cartoee plot?

Open GokulGeo opened this issue 4 years ago • 1 comments

Hi, I am trying to add a scalebar using the sample scripts in geemap. But I am getting wrong results. The pixel size of the satellite imagery is 10m.The output is coming as

image

Which is wrong,

The script which I used is,

oi =m.draw_last_feature
geom = roi.geometry()
coords = geom.coordinates().getInfo()
zoom_region = [coords[0][0][0], coords[0][0][1], coords[0][2][0], coords[0][2][1]]

fig = plt.figure(figsize=(10,20))

vis = {
    "bands":["VV"],
    "min":-25,
    "max":0,
    "palette":['aqua', 'black']
}

# use cartoee to get a map
ax = cartoee.get_map(Sentinel_1,vis_params=vis,region=zoom_region)

# add gridlines to the map at a specified interval
cartoee.add_gridlines(ax,interval=[0.005,0.005],linestyle=":")

ax.set_title(
    label = 'Sentinel-1, October 5,2020 ',
    fontsize = 15
)

scalebar = ScaleBar(10) # 1 pixel = 0.2 meter
ax.add_artist(scalebar)
plt.show()

Kindly suggest ways to fix it. Thank you.

GokulGeo avatar Dec 11 '20 07:12 GokulGeo

Based on the comment in your code snippet, "1 pixel = 0.2 meter", the dx argument should be 0.2:

scalebar = ScaleBar(0.2, "m")

Does this help? I don't know the cartoee package. Other users using geopandas had a similar issue, and the following note was added to the documentation:

Special notes for geospatial plots: If you are plotting geospatial coordinates (such as scatterplots of the location of structures, geopandas geodataframe plots, etc.), dx needs to be set differently depending on the coordinate system:

  • For UTM based coordinate system, where the X and Y are in meters, simply set dx = 1.
  • For WGS or NAD based coordinate system, where X and Y are in latitude (Y) and longitude (X), compute the distance between two points at the latitude (Y) you wish to have the scale represented and are also one full degree of longitude (X) apart, in meters. For example, dx = great_circle_distance((X, Y), (X + 1, Y))

ppinard avatar Jan 01 '21 13:01 ppinard