Python Forum

Full Version: for loop on stacked images
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear All,

I have read each single image from stacked file *.tif separately, using the following code,

dataset = rasterio.open('D:\data_stacked_2015.tif')

fig, (axes1, axes2, axes3) = pyplot.subplots(1,3, figsize=(21,7))
show((dataset, 64), ax = axes1, cmap='gray', title='red channel')
show((dataset, 65), ax = axes2, cmap='gray', title='green channel')
show((dataset, 66), ax = axes3, cmap='gray', title='blue channel')

for ax in axes1, axes2, axes3:
ax.axis('off')
plt.show()

But, What I'd like to do is, to read the whole stacked images as subplot, using for loop, However, the following doesn't work,


dataset = rasterio.open('D:\data_stacked_2015.tif')

# Create subplots
rows, cols = 10, 7
fig, ax = pyplot.subplots(rows, cols,
sharex='col',
sharey='row',
figsize=(21,7))

for axes in range(10):
for col in range(7):
image = show((dataset), axes, cmap='gray')
plt.show()

Any suggestions pleas, and many thanks in advance.
How could I read the stacked file *.tif separately at once, instead of one by one as below! , using for loop,

Or, How to convert the following code to for loop?

import rasterio
from rasterio.plot import show
from matplotlib import pyplot
import matplotlib.pyplot as plt


# to display bands one by one
dataset = rasterio.open('D:\data_stacked_2015.tif')

fig, (axes1, axes2, axes3) = pyplot.subplots(1,3, figsize=(21,7))
show((dataset, 64), ax = axes1, cmap='gray', title='red channel')
show((dataset, 65), ax = axes2, cmap='gray', title='green channel')
show((dataset, 66), ax = axes3, cmap='gray', title='blue channel')

for ax in axes1, axes2, axes3:
    ax.axis('off')
plt.show()
Please do not send private mail.
every post is viewed by all moderators, and answered by the first one with the appropriate knowledge.
Thanks for your reply, Would you please to share your knowledge to solve the above issue, since I'm still in my first steps in python.