How can I add a colorbar after using rio.plot.show? I've tried a bunch of things but have gotten various errors
Here's one way I tried:
fig, ax = plt.subplots(figsize = (16, 16))
retted = rio.plot.show(ds, ax=ax, cmap='Greys_r')
fig.colorbar(retted, ax=ax)
plt.title("Original")
plt.show()
This has error: AttributeError: 'AxesSubplot' object has no attribute 'get_array'
I did what david suggested above and it worked!
fig, ax = plt.subplots(figsize=(5, 5))
# use imshow so that we have something to map the colorbar to
image_hidden = ax.imshow(image_data,
cmap='Greys',
vmin=-30,
vmax=30)
# plot on the same axis with rio.plot.show
image = rio.plot.show(image_data,
transform=src.transform,
ax=ax,
cmap='Greys',
vmin=-30,
vmax=30)
# add colorbar using the now hidden image
fig.colorbar(image_hidden, ax=ax)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With