我有一个栅格数据,其中包含40个波段总数。以下是我的数据头:

因此,我创建了一个代码,它可以读取和计算这样的波段的平均值:
prof = train_pts.groupby (['classes']).mean ()
fig = plt.figure(figsize = (17,20))
band_n = [ 'Band [2,6,11,16]', 'Band [3,7,12,17]', 'Band [4,8,13,30]', 'Band [20,22,14,26]', 'Band [2,26,11,30]', 'Band [2,26,11,30]']
band_name = ['Sentinel-2 B2'], ['Sentinel-2 B3']
n = 1
for ba in band_n :
ax = fig.add_subplot(4,2,n)
ax.title.set_text(band_name)
band_val = prof[prof.columns[prof.columns.to_series().str.contains(ba)]]
for index, row in band_val.iterrows():
color = cmap (index)
ax.plot (row,color=color)
ax.autoscale(enable=True, axis="both", tight=None)
ax.set_xticklabels([(str (band_name) for band_name in range(1, len(row)+1))])
ax.legend(loc='best', fontsize='small', ncol=2, labels=class_names)
n=n+1例如,对于哨兵-2 B2,它计算每个点的这些带的平均值并绘制它们。但是我在为x,y轴的标签和图的标题而挣扎。我在这里要做的是把'Band [2,6,11,16]'情节的标签设置为'Sentinel-2 B2','Band [3,7,12,17]'情节的标签为['Sentinel-2 B3'],然后继续这样下去.但它为我创作的所有情节都写了同样的标题。如下所示:

我还能试试什么?
发布于 2022-06-18 20:09:38
在您的代码中,乐队名称永不更改:
band_name = ['Sentinel-2 B2'], ['Sentinel-2 B3']
n = 1
for ba in band_n :
ax = fig.add_subplot(4,2,n)
ax.title.set_text(band_name) # this is unaffected by the loop我想你的意思是……利用枚举内置函数
band_name = ['Sentinel-2 B2', 'Sentinel-2 B3']
for i, ba in enumerate(band_n):
ax = fig.add_subplot(4,2,i + 1)
ax.title.set_text(band_name[i])但是您没有足够的band_names来满足波段的数量,所以在这段代码开始工作之前,您需要修复band_name列表。
https://stackoverflow.com/questions/72668952
复制相似问题