0

How can I plot the two measurement parameters (seasonal cover and permanent water cover) in the same axis as I want to compare them?

I have this code:

#load the cgls product
ds_cgls_builtcover = dc.load(product='cgls_landcover', time='2019', 
                             measurements=['seasonalwater_cover_fraction','permanentwater_cover_fraction'], 
                             like=ds_cgls.geobox).squeeze()

#plot the dataset
fig, (ax0, ax1) = plt.subplots(1,2, figsize=(24,9), sharex=True, sharey=True)
ds_cgls_builtcover.seasonalwater_cover_fraction.plot(ax=ax[0])
ds_cgls_builtcover.permanentwater_cover_fraction.plot(ax=ax[0])
plot_lulc(ds_cgls[measurements], product='CGLS', legend=True, ax=ax[1])

ax[0].set_title('seasonalwater_cover %')
ax[1].set_title('CGLS Landcover')
plt.tight_layout();

1 Answer 1

0

To overlay the two measurements on a plot, you can try the following code:

# Load the cgls product.
ds_cgls_builtcover = dc.load(product='cgls_landcover', time='2019', 
                             measurements=['seasonalwater_cover_fraction','permanentwater_cover_fraction'], 
                             like=ds_cgls.geobox).squeeze()


# For both measurements the no data value is 255. 
# Based on the Digital Earth Africa CGLS data catalogue page
# https://docs.digitalearthafrica.org/en/latest/data_specs/CGLS_LULC_specs.html
# Mask the no data values. 
ds_cgls_builtcover = ds_cgls_builtcover.where(ds_cgls_builtcover != 255)

# Plot the measurements on the same axis.
fig, ax = plt.subplots(figsize=(24,9))
# Plot the first measurement with a different colormap from the second.
cmap1="Blues"
cmap2="Greens"
ds_cgls_builtcover.seasonalwater_cover_fraction.plot(cmap=cmap1, ax=ax)
# Make the second plot slightly transparent. 
ds_cgls_builtcover.permanentwater_cover_fraction.plot(cmap=cmap2, ax=ax, alpha=0.5)

The above code produces this plot: enter image description here

To plot the measurements side by side you can try the following code:

# Load the cgls product.
ds_cgls_builtcover = dc.load(product='cgls_landcover', time='2019', 
                             measurements=['seasonalwater_cover_fraction','permanentwater_cover_fraction'], 
                             like=ds_cgls.geobox).squeeze()


# For both measurements the no data value is 255. 
# Based on the Digital Earth Africa CGLS data catalogue page
# https://docs.digitalearthafrica.org/en/latest/data_specs/CGLS_LULC_specs.html
# Mask the no data values. 
ds_cgls_builtcover = ds_cgls_builtcover.where(ds_cgls_builtcover != 255)

# Plot the measurements side by side.
fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(24,9), sharex=True, sharey=True)
ds_cgls_builtcover.seasonalwater_cover_fraction.plot(cmap="viridis", ax=ax0)
ds_cgls_builtcover.permanentwater_cover_fraction.plot(cmap="viridis", ax=ax1)

Which results in the following plot: enter image description here

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.