matplotlib设置X轴

发布于 2025-02-08 20:49:28 字数 1394 浏览 0 评论 0原文

我试图通过使用我创建的ShapeFile点的反射值来可视化由40个带有Matplotlib的频段组成的栅格数据。

例如,在我下面写的代码中,band_n变量的平均为33,36,36,39,40,并用B2标题绘制它。在这方面,我期望每个图的X轴上有4个滴答。

    prof = train_pts.groupby (['classes']).mean ()
fig = plt.figure(figsize = (17,20))
band_n = [ 'Band [33,36,39,40]', '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 = ['B2', 'B3', 'B4', 'B8', 'NDVI', 'VV', 'VH']
n = 1
for i, ba in enumerate(band_n):
    ax = fig.add_subplot(4,2,i + 1)
    ax.title.set_text(band_name[i])
    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.set_xticklabels([(str (band_n) for band_n in range(1, len(row)+1))]) #replace the column names with numbers
    ax.legend(loc='best', fontsize='small', ncol=1, labels=class_names)
n=n+1

但是当我运行此操作时,我会通过此图会警告:

​还是有更简单的方法?

ax.set_xticklabels([(str (band_n) for band_n in range(1, len(row)+1))]) #replace the column names with numbers 

I am trying to visualize the raster data consisting of 40 bands with matplotlib by taking the reflection values ​​with the shapefile points that I created.

enter image description here

For example, in the code I wrote below, the band_n variable takes the average of Band 33,36,39,40 and plots it with the B2 title. In this respect, I am expecting 4 ticks on the x-axis of each plot.

    prof = train_pts.groupby (['classes']).mean ()
fig = plt.figure(figsize = (17,20))
band_n = [ 'Band [33,36,39,40]', '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 = ['B2', 'B3', 'B4', 'B8', 'NDVI', 'VV', 'VH']
n = 1
for i, ba in enumerate(band_n):
    ax = fig.add_subplot(4,2,i + 1)
    ax.title.set_text(band_name[i])
    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.set_xticklabels([(str (band_n) for band_n in range(1, len(row)+1))]) #replace the column names with numbers
    ax.legend(loc='best', fontsize='small', ncol=1, labels=class_names)
n=n+1

But when I run this I get warnings with this plots :

Isn't this code suitable for converting the band_n variable to string and printing it on the x axis? Or is there an easier way?

ax.set_xticklabels([(str (band_n) for band_n in range(1, len(row)+1))]) #replace the column names with numbers 

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文