Skip to content

plot classified image #404

@12rambau

Description

@12rambau

The plot method from the ImageAccessor is plotting continuous images and has lots of difficulties to plot classified images. I tried to play with the cmap of the following graph but never managed to make it work:

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

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

import matplotlib.pyplot as plt

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()

image

If someone finds a way to create a class clolorbar then it should be added to the documentation else a PR will be welcomed in the source code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions