contextily icon indicating copy to clipboard operation
contextily copied to clipboard

Force basemap to be greyscale

Open matthew-law opened this issue 3 years ago • 3 comments

It would be useful to be able to turn any basemap greyscale. I've tried passing cmap = 'gray' to cx.add_basemap (which I think calls plt.imshow), but haven't been able to get anything working.

Example of the kind of case in which a greyscale option for the basemap would be handy in the interest of reducing visual clutter / foregrounding the overlying data without losing too much of the information provided by the basemap: image

matthew-law avatar Aug 30 '22 22:08 matthew-law

This is a good idea! I guess now you should be able to get there by manipulating the output ax object but that's suboptimal. Maybe one general way of allowing this is to let the user pass keywords for imshow in a imshow_kwds dict?

We can flesh out ideas here and, if you have bandwidth, I'd very much welcome PRs :-)

darribas avatar Sep 28 '22 13:09 darribas

Two notes on this.

  1. It is often suboptimal and we should prefer using real B&W tiles than forcing grayscale on otherwise coloured image.
  2. We may not be allowed to do it for some tiles. I'd assume that their T&C will prohibit tampering with the image itself.

martinfleis avatar May 08 '23 18:05 martinfleis

If someone wanted to do that anyway, here's a nice documentation https://scikit-image.org/docs/dev/auto_examples/color_exposure/plot_rgb_to_gray.html (but ensure that we reimplement it on top of our numpy array and do not depend on scikit-image).

martinfleis avatar May 27 '23 00:05 martinfleis