3

I am trying to plot GEE images as standalone figures (e.g., JPEG or PNG) for publications, however, I have not been able to find a standard method for doing that. For example, I have a landcover image and want to plot a bounding box of landcover pixels together with a legend that describes the label corresponding to the colors of each pixel. Is there a way to use something like Matplotlib in Python to create the figure? How do I do that? Here is a sample GEE image and how I would like the final product to look like:

import ee
ee.Initialize()

landcover = ee.ImageCollection('USGS/NLCD_RELEASES/2016_REL').filter(ee.Filter.eq('system:index', '2016')).first().select('landcover')

roi = ee.FeatureCollection(ee.Geometry.Polygon(
    [[[-121.214213, 39.102459],
      [-121.214213, 39.109467],
      [-121.199295, 39.109467],
      [-121.199295, 39.102459],
      [-121.214213, 39.102459]]]))

enter image description here

1 Answer 1

0

You can use the geetools extention and all the matplolib bindings that have been coded there. Specifically to create a static map of an image you can use the plot

For your sepecific use case, using the specified roi and landcover image, that would do:

import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter

fig, ax = plt.subplots()

landcover.geetools.plot(bands = ["landcover"], ax=ax, region=roi)

ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
ax.tick_params(axis='both', which='both', length=0, labelbottom=False, labelleft=False)
ax.set_title("Landcover over a random AOI")
fig.colorbar(ax.images[0], label="landcover")

plt.show()

figure

You can then play with the cmap and colorbar of the figure to make it fit exactly with your need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.