设置Geopandas图块的标签

发布于 2025-02-09 02:51:07 字数 1334 浏览 1 评论 0原文

我有一个栅格数据,其中包含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:

enter image description here

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:

enter image description here

What can I try else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2025-02-16 02:51:07

在您的代码中,频段名称永远不会更改:

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 list列表,然后此代码可以正常工作。

In your code, band name never changes:

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

I think you mean something along these lines... making use of the enumerate built in function

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])

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文