matplotlib设置X轴
我试图通过使用我创建的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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论