设置Geopandas图块的标签
我有一个栅格数据,其中包含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
每个点并绘制它们。但是我在X,Y Axis标签和情节标题上挣扎。我想在这里做的是设置'band [2,6,11,16]'
绘图标签为'sentinel-2 b2'
,'band [3,7,12,17]'绘制标签为['sentinel-2 b3']
,然后继续这样做...但是它为所有绘图编写了相同的标题我创建了。这样:
我还能尝试什么?
I have a raster data which contains 40 band total. Here is the head of my data:
So I created a code that can read and calculate the mean of the bands like this:
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
For example, for Sentinel-2 B2 it calculates the mean of these bands for each point and plot them. But I am struggling with x, y axis labels and the title of the plots. What I wanted to do here is set the 'Band [2,6,11,16]'
plot's label as 'Sentinel-2 B2'
, 'Band [3,7,12,17]'
plot's label as ['Sentinel-2 B3']
and go on like this... But it write the same title for all plots that I created. Like this:
What can I try else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码中,频段名称永远不会更改:
我认为您的意思是这些行...使用枚举函数内置的,
但您没有足够的band_names来用于频段的数量,因此您需要修复
band_name
list列表,然后此代码可以正常工作。In your code, band name never changes:
I think you mean something along these lines... making use of the enumerate built in function
But you don't have enough band_names for the number of bands, so you'll need to fix your
band_name
list before this code will work.