abhijeetsarkargis commited on
Commit
314c9cc
·
1 Parent(s): cf478c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -9,8 +9,11 @@ def visualize_image(file_path):
9
  # Get the number of bands in the image
10
  num_bands = dataset.count
11
 
 
 
 
12
  # Create subplots to visualize each band
13
- fig, axes = plt.subplots(2, 5, figsize=(30, 30))
14
 
15
  # Loop through each band and plot it
16
  for band_index in range(1, num_bands + 1):
@@ -18,13 +21,17 @@ def visualize_image(file_path):
18
  band = dataset.read(band_index)
19
 
20
  # Determine the subplot position
21
- row_index = (band_index - 1) // 5
22
- col_index = (band_index - 1) % 5
23
 
24
  # Plot the band on the corresponding subplot
25
- axes[row_index, col_index].imshow(band, cmap='jet')
26
  axes[row_index, col_index].set_title(f"Band {band_index}")
27
 
 
 
 
 
28
  # Adjust the layout and display the visualization
29
  plt.tight_layout()
30
 
 
9
  # Get the number of bands in the image
10
  num_bands = dataset.count
11
 
12
+ # Calculate the number of rows required for subplots
13
+ num_rows = (num_bands + 1) // 2
14
+
15
  # Create subplots to visualize each band
16
+ fig, axes = plt.subplots(num_rows, 2, figsize=(10, 6 * num_rows))
17
 
18
  # Loop through each band and plot it
19
  for band_index in range(1, num_bands + 1):
 
21
  band = dataset.read(band_index)
22
 
23
  # Determine the subplot position
24
+ row_index = (band_index - 1) // 2
25
+ col_index = (band_index - 1) % 2
26
 
27
  # Plot the band on the corresponding subplot
28
+ axes[row_index, col_index].imshow(band, cmap='gray')
29
  axes[row_index, col_index].set_title(f"Band {band_index}")
30
 
31
+ # Remove any empty subplots if there are odd number of bands
32
+ if num_bands % 2 != 0:
33
+ fig.delaxes(axes[num_rows - 1, 1])
34
+
35
  # Adjust the layout and display the visualization
36
  plt.tight_layout()
37