如何将一系列图像绘制到特定地图上
How to plot series of images onto a particular map
我想以特定模式绘制图像,如下图所示
我想了解什么是使用 python 绘制图像的最佳方式。我使用了以下方法以网格模式绘制图像。
输出看起来像这样
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib as mpl
from matplotlib.dates import date2num
import matplotlib.dates as mdates
from mpl_toolkits.axes_grid1 import ImageGrid
img0 = f['B00'][i_ant, :, :]
img1 = f['B01'][i_ant, :, :]
img2 = f['B02'][i_ant, :, :]
img3 = f['B03'][i_ant, :, :]
img_arr = [img0,img1,img2,img3]
fig = plt.figure(figsize=(5., 5.))
grid = ImageGrid(fig, 111,
nrows_ncols=(2, 2), # creates 2x2 grid of axes
axes_pad=0, # pad between axes
)
for ax, im in zip(grid, img_arr):
ax.imshow(im)
plt.show()
对于方形螺旋线的每一层,都会添加两条边,除了最后一层只需要一条边。 i,j
位置每步递增或递减1,每转90度转90度
这是它的工作原理:
import matplotlib.pyplot as plt
import numpy as np
N = 6
fig = plt.figure(figsize=(16, 18), constrained_layout=True)
spec = fig.add_gridspec(ncols=N * 2 - 1, nrows=N * 2 - 1)
i, j = N - 2 + N % 2, N - 1
dir_i, dir_j = 1, - 1
plot_num = 0
for k in range(1, N + 1):
for _ in range(2): # add two strokes of k subplots (only 1 when k==N)
for _ in range(k):
ax = fig.add_subplot(spec[i, j])
ax.imshow(np.random.rand(3, 3))
ax.set_xlabel(f'{plot_num} [{k}]', fontsize=18)
plot_num += 1
i += dir_i
j += dir_j
if k == N:
break
dir_i, dir_j = -dir_j, dir_i
plt.show()
要准确复制原始编号,可以绘制一些同心正方形。对于奇数N
,最后一个方格很不规则,只有2条边,最后一行跳到对面,比其余的少一个方格
对于2和3奇怪的编号,可以引入一些重新编号:
import matplotlib.pyplot as plt
import numpy as np
N = 6
fig = plt.figure(figsize=(16, 18), constrained_layout=True)
spec = fig.add_gridspec(ncols=2 * N - 1, nrows=2 * N - 1)
plot_num = 0
for k in range(2, N + 2, 2):
# i, j = N - 2 + N % 2, N - 1
i, j = N - k + N % 2, N - 1
dir_i, dir_j = 1, - 1
for side in range(4): # add four strokes of k subplots (only 2 when k==N)
for _ in range(k - 1):
ax = fig.add_subplot(spec[i, j])
modified_plot_num = 5 - plot_num if plot_num in (2, 3) else plot_num
ax.imshow(np.random.rand(6, 6), cmap='inferno')
ax.set_xlabel(f'{modified_plot_num} [{k}]', fontsize=18)
plot_num += 1
i += dir_i
j += dir_j
if plot_num == N * N: # for odd N, the very last cell should be skipped
break
if k == N + 1:
if side == 0: # for last side of uneven square: jump to the other side
dir_i, dir_j = -dir_i, -dir_j
i, j = i - 1, 2 * N - 2
elif side == 1:
break
dir_i, dir_j = -dir_j, dir_i
plt.show()
我想以特定模式绘制图像,如下图所示
我想了解什么是使用 python 绘制图像的最佳方式。我使用了以下方法以网格模式绘制图像。
输出看起来像这样
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib as mpl
from matplotlib.dates import date2num
import matplotlib.dates as mdates
from mpl_toolkits.axes_grid1 import ImageGrid
img0 = f['B00'][i_ant, :, :]
img1 = f['B01'][i_ant, :, :]
img2 = f['B02'][i_ant, :, :]
img3 = f['B03'][i_ant, :, :]
img_arr = [img0,img1,img2,img3]
fig = plt.figure(figsize=(5., 5.))
grid = ImageGrid(fig, 111,
nrows_ncols=(2, 2), # creates 2x2 grid of axes
axes_pad=0, # pad between axes
)
for ax, im in zip(grid, img_arr):
ax.imshow(im)
plt.show()
对于方形螺旋线的每一层,都会添加两条边,除了最后一层只需要一条边。 i,j
位置每步递增或递减1,每转90度转90度
这是它的工作原理:
import matplotlib.pyplot as plt
import numpy as np
N = 6
fig = plt.figure(figsize=(16, 18), constrained_layout=True)
spec = fig.add_gridspec(ncols=N * 2 - 1, nrows=N * 2 - 1)
i, j = N - 2 + N % 2, N - 1
dir_i, dir_j = 1, - 1
plot_num = 0
for k in range(1, N + 1):
for _ in range(2): # add two strokes of k subplots (only 1 when k==N)
for _ in range(k):
ax = fig.add_subplot(spec[i, j])
ax.imshow(np.random.rand(3, 3))
ax.set_xlabel(f'{plot_num} [{k}]', fontsize=18)
plot_num += 1
i += dir_i
j += dir_j
if k == N:
break
dir_i, dir_j = -dir_j, dir_i
plt.show()
要准确复制原始编号,可以绘制一些同心正方形。对于奇数N
,最后一个方格很不规则,只有2条边,最后一行跳到对面,比其余的少一个方格
对于2和3奇怪的编号,可以引入一些重新编号:
import matplotlib.pyplot as plt
import numpy as np
N = 6
fig = plt.figure(figsize=(16, 18), constrained_layout=True)
spec = fig.add_gridspec(ncols=2 * N - 1, nrows=2 * N - 1)
plot_num = 0
for k in range(2, N + 2, 2):
# i, j = N - 2 + N % 2, N - 1
i, j = N - k + N % 2, N - 1
dir_i, dir_j = 1, - 1
for side in range(4): # add four strokes of k subplots (only 2 when k==N)
for _ in range(k - 1):
ax = fig.add_subplot(spec[i, j])
modified_plot_num = 5 - plot_num if plot_num in (2, 3) else plot_num
ax.imshow(np.random.rand(6, 6), cmap='inferno')
ax.set_xlabel(f'{modified_plot_num} [{k}]', fontsize=18)
plot_num += 1
i += dir_i
j += dir_j
if plot_num == N * N: # for odd N, the very last cell should be skipped
break
if k == N + 1:
if side == 0: # for last side of uneven square: jump to the other side
dir_i, dir_j = -dir_i, -dir_j
i, j = i - 1, 2 * N - 2
elif side == 1:
break
dir_i, dir_j = -dir_j, dir_i
plt.show()