opendatacube / datacube-ows

Open Data Cube Open Web Services
Other
69 stars 37 forks source link

Backend default to Agg preventing plotting when testing styles programmatically #861

Closed rtaib closed 1 year ago

rtaib commented 2 years ago

Description

When testing the styles programmatically in a Notebook, as per the documentation the plots do not show because the backend is set to Agg by datacube_ows/styles/ramp.py. The user must use %matplotlib inline before using, e.g., plot_image_with_style_cfg()

Steps to Reproduce

In a Notebook, pull some data from ODC and define a rgb_cfg style, just as shown in the docs. Then:

from datacube_ows.styles.api import StandaloneStyle, apply_ows_style_cfg, xarray_image_as_png, plot_image_with_style_cfg

plot_image_with_style_cfg(rgb_cfg, data, x="longitude", y="latitude")

This does not produce any plot, and indeed, plt.get_backend() returns agg.

Context (Environment)

datacube-ows version (datacube-ows --version):

1.8.28

ows_config.py file (link, sample code)

N/A

datacube product metadata (datacube product show product_name)

N/A

SpacemanPaul commented 2 years ago

That's odd - nothing relevant has changed at our end since the last time I tested the styling API in a Notebook.

Something must have changed in Jupyter or matplotlib I guess.

Should be fixable by calling matplotlib.use("nbAgg") inside datacube_ows.styles.base.plot_image().

rtaib commented 2 years ago

Ah! You must be right, because I'm pretty sure it was working a few months ago (v1.8.26 then) and I don't think this bit of code changed in the meantime. However, our JLab or matplotlib may have been updated. If your suggested fix works, that would be great, though.

rtaib commented 1 year ago

I see this issue is still open. For what it's worth, the changes @SpacemanPaul made in #886 seem to have fixed the issue for me, tested with v1.8.33. Thanks!