Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rio.plot.show with colorbar?

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'

like image 371
rasen58 Avatar asked Apr 20 '20 16:04

rasen58


Video Answer


1 Answers

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)
like image 192
steven Avatar answered Sep 30 '22 04:09

steven