cartoee.add_scale_bar_lite() issue
caomy7 opened this issue ยท 6 comments
Environment Information
Please run the following code on your computer and share the output with us so that we can better debug your issue:
import ee
import geemap
import cartopy.crs as ccrs
# import the cartoee functionality from geemap
from geemap import cartoee
Description
Scale bar seems have a problem. I guess maybe the projection problem, but I can not solve.
What I Did
import datetime
import ee
import geemap
Map = geemap.Map()
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
# import the cartoee functionality from geemap
from geemap import cartoee
year = 2001
startDate = str(year) +'-01-01'
endDate = str(year) +'-12-31'
daymet= ee.ImageCollection('NASA/ORNL/DAYMET_V4').filter(ee.Filter.date(startDate, endDate));
tmax = daymet.select('tmax').first();
fig = plt.figure(figsize=(10, 8))
# region = [-180, 0, 0, 90]
vis = {
"min": -40.0,
"max": 30.0,
"palette": ['1621A2', '#0000FF', '#00FF00', '#FFFF00', '#FF0000'],
};
Map.setCenter(-110.21, 35.1, 4);
# target_crs = region.projection().crs()
# Corr = crossCorr.reproject(crs=target_crs, scale=500)
# use cartoee to get a map
ax = cartoee.get_map(tmax, region=[-180, 0, 0, 90], vis_params=vis,ccrs=ccrs.PlateCarree())
# add gridlines to the map at a specified interval
# cartoee.add_gridlines(ax, interval=[30, 30], linestyle=":")
cartoee.add_gridlines(ax, interval=[30, 30], linestyle="--")
# add a colorbar to the map using the visualization params we passed to the map
cartoee.add_colorbar(ax, vis, loc="bottom", label="Correlation", orientation="horizontal")
# ax.set_title(label='Correlation', fontsize=15)
# add coastlines using the cartopy api
ax.coastlines(color="red")
# add north arrow
cartoee.add_north_arrow(ax, text="N", xy=(0.1, 0.35), arrow_length=0.15,text_color="black", arrow_color="black", fontsize=20)
# add scale bar
cartoee.add_scale_bar_lite(ax, length=100, xy=(0.1, 0.05), linewidth=8, fontsize=20, color="red", unit="km", ha='center', va='bottom')
show()
even though I had a reprojection:
image_proj = tmax.reproject('EPSG:4326')
It also doesn't work
Thank you very much,you are so kind~ But the scale bar seems a little weird
I wonder the scale bar should be like a line or ruler rather than a point. But my result is a point in this figure.
For continental maps of North America, scale bars and north arrows are useless. The unit distance near the equator is very different from the one near the north pole. You should remove them.
cartoee.add_scale_bar_lite(ax, length=2000, xy=(0.2, 0.1), linewidth=3, fontsize=10, color="red", unit="km", ha='left', va='bottom')
It makes sense more. Thank you very very much~