# all imports should go here\nimport pandas as pd\nimport sys\nimport os\nimport subprocess\nimport datetime\nimport platform\nimport datetime\nimport math\n\nimport matplotlib.pyplot as plt\n#import seaborn as sb\n\nfrom geemap import cartoee\n\nimport cartopy\nimport cartopy.crs as ccrs\nfrom cartopy.io.img_tiles import OSM\nimport cartopy.feature as cfeature\nfrom cartopy.io import shapereader\nfrom cartopy.io.img_tiles import StamenTerrain\nfrom cartopy.io.img_tiles import GoogleTiles\nfrom owslib.wmts import WebMapTileService\n\nfrom matplotlib.path import Path\nimport matplotlib.patheffects as PathEffects\nfrom matplotlib import patheffects\nimport matplotlib.patches as mpatches\nimport matplotlib.lines as mlines\n\nimport numpy as np\n\n\nfig = plt.figure(figsize=(10,12))\n\n# ------------------------------- Surrounding frame ------------------------------\n# set up frame full height, full width of figure, this must be called first\n\nleft = -0.05\nbottom = -0.05\nwidth = 1.1\nheight = 1.05\nrect = [left,bottom,width,height]\nax3 = plt.axes(rect)\n\n\n\n# turn on the spines we want, ie just the surrounding frame\nplt.axis('off')\n\n\nax3.text(0.01,0.01,'© Don Cameron, 2017: net-analysis.com. '+\n 'Map generated at '+datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"), fontsize=8)\n\n\n\n# --------------------------------- Main Map -------------------------------------\n#\n# set up main map almost full height (allow room for title), right 80% of figure\nBORDERS2_10m = cartopy.feature.NaturalEarthFeature(\n 'cultural', 'admin_1_states_provinces','10m', edgecolor='black', facecolor='none'\n)\n\nLAND_10m = cartopy.feature.NaturalEarthFeature(\n 'physical', 'land', '10m',edgecolor='face',facecolor=cartopy.feature.COLORS['land']\n)\n\nRIVERS_10m = cartopy.feature.NaturalEarthFeature(\n 'physical', 'rivers_lake_centerlines', '10m',edgecolor=cartopy.feature.COLORS['water'],facecolor='none'\n)\n\nleft = 0.2\nbottom = 0\nwidth = 0.8\nheight = 0.90\nrect = [left,bottom,width,height]\n\nax = plt.axes(rect, projection=ccrs.PlateCarree())\nax.set_extent((150, 155, -30, -23))\n\n\nax.coastlines(resolution='10m', zorder=2)\n\n#land polygons, including major islands, use cartopy default color\nax.add_feature(LAND_10m)\nax.add_feature(RIVERS_10m)\nax.add_feature(BORDERS2_10m, edgecolor='grey')\n\nax.stock_img()\n# stock image is good enough for example, but OCEAN_10m could be used, but very slow\n# ax.add_feature(OCEAN_10m)\n\nax.gridlines(draw_labels=True, xlocs=[150, 152, 154, 155])\n\ncartoee.add_scale_bar(ax, length=100, fontsize=16)\ncartoee.add_north_arrow(ax, xy = (0.9, 0.95))\n\n\n# ---------------------------------Locating Map ------------------------\n#\n# set up index map 20% height, left 16% of figure\nleft = 0\nbottom = 0\nwidth = 0.16\nheight = 0.2\nrect = [left,bottom,width,height]\n\n\nax2 = plt.axes(rect, projection=ccrs.PlateCarree())\nax2.set_extent((110,160, -45, -10))\n# ax2.set_global() will show the whole world as context\n\nax2.coastlines(resolution='110m', zorder=2)\nax2.add_feature(cfeature.LAND)\nax2.add_feature(cfeature.OCEAN)\n\nax2.gridlines()\n\n\nlon0,lon1,lat0,lat1 = ax.get_extent()\nbox_x = [lon0, lon1, lon1, lon0, lon0]\nbox_y = [lat0, lat0, lat1, lat1, lat0]\n\nplt.plot(box_x, box_y, color='red', transform=ccrs.Geodetic())\n\n\n# -------------------------------- Title -----------------------------\n# set up map title top 4% of figure, right 80% of figure\n\nleft = 0.2\nbottom = 0.95\nwidth = 0.8\nheight = 0.04\nrect = [left,bottom,width,height]\nax6 = plt.axes(rect)\nax6.text(0.5, 0.0,'Multi-Axes Map Example', ha='center', fontsize=20)\nplt.axis('off')\n\n\n# ------------------------------------ Legend -------------------------------------\n\n# legends can be quite long, so set near top of map (0.4 - bottom + 0.5 height = 0.9 - near top)\nleft = 0\nbottom = 0.4\nwidth = 0.16\nheight = 0.5\nrect = [left,bottom,width,height]\nrect = [left,bottom,width,height]\nax5 = plt.axes(rect)\n\n# create an array of color patches and associated names for drawing in a legend\n# colors are the predefined colors for cartopy features (only for example, Cartopy names are unusual)\ncolors = sorted(cartopy.feature.COLORS.keys())\n\n# handles is a list of patch handles\nhandles = []\n# names is the list of corresponding labels to appear in the legend\nnames = []\n\n# for each cartopy defined color, draw a patch, append handle to list, and append color name to names list\nfor c in colors:\n patch = mpatches.Patch(color=cfeature.COLORS[c], label=c)\n handles.append(patch)\n names.append(c)\n#end for\n\n# do some example lines with colors\nriver = mlines.Line2D([], [], color=cfeature.COLORS['water'], marker='',\n markersize=15, label='river')\ncoast = mlines.Line2D([], [], color='black', marker='',\n markersize=15, label='coast')\nbdy = mlines.Line2D([], [], color='grey', marker='',\n markersize=15, label='state boundary')\nhandles.append(river)\nhandles.append(coast)\nhandles.append(bdy)\nnames.append('river')\nnames.append('coast')\nnames.append('state boundary')\n\n\n# create legend\nax5.legend(handles, names)\nax5.set_title('Legend',loc='left')\nplt.axis('off')\n\nplt.savefig(\"test.png\", bbox_inches='tight')\n\nplt.show()\n\n
-
Hi, Merry Christmas¡. Exploring some ways to graph GEE images I found this interesting example: The example uses multiple axes to generate the following image: I tried some |
Beta Was this translation helpful? Give feedback.
-
This is a nice example. Do you have a sample notebook for testing? I like the legend and scale bar. We can probably incorporate these into cartoee. |
Beta Was this translation helpful? Give feedback.
-
This is the code that summarizes the example, I tested it in Google Colab.
|
Beta Was this translation helpful? Give feedback.
-
Dear Dr. Wu, Happy new year. I followed your example but got these errors
(after calling update_package()). Here is the error message.
[image: image.png]
…On Fri, Jan 1, 2021 at 4:57 AM ErikSeras ***@***.***> wrote:
Thank you @giswqs <https://github.com/giswqs>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#238 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE5J3HU6VMIDBF2VXGY4YCLSXTQUDANCNFSM4VJNURHQ>
.
|
Beta Was this translation helpful? Give feedback.
-
[image: Untitled.png]
…On Fri, Jan 1, 2021 at 9:14 AM Qiusheng Wu ***@***.***> wrote:
Your image attachment does not show up.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#238 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE5J3HSHXCTIMS4OD3PNOWDSXUOXVANCNFSM4VJNURHQ>
.
|
Beta Was this translation helpful? Give feedback.
This is the code that summarizes the example, I tested it in Google Colab.