本文介绍了底图子图出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要绘制一个具有n个底图子图的图.但是当我这样做时,所有的值都绘制在第一个子图上.

I need to make a plot with n number of basemap subplots. But when I am doing this the all the values are plotted on the first subplot.

我的数据是一组'n'个矩阵,存储在 data_all 中.

My data is a set of 'n' matrixes, stored in data_all.

f, map = plt.subplots(n,sharex=True, sharey=True, figsize=(20,17))

plt.subplots_adjust(left=None, bottom=None, right=None, top=None,
                    wspace=None, hspace=0.)

for i in range(n):
    map = Basemap(projection='merc', lat_0=0, lon_0=180,
                  resolution='h', area_thresh=0.1,
                  llcrnrlon=0, llcrnrlat=-45,
                  urcrnrlon=360, urcrnrlat=45)
    map.drawcoastlines(linewidth=0.5)
    map.drawmapboundary()
    map.drawmapboundary()
    nx = data_all.shape[0]
    ny = data_all.shape[1]
    lon, lat = map.makegrid(ny[i], nx[i])
    z,y = map(lon, lat)
    cs = map.contourf(z, y, data_all[i])

推荐答案

我暂时无法测试,但基本上,您只需要告诉底图使用哪些轴即可.

I can't test it at the moment, but basically, you just need to tell basemap which axes to use.

例如:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

fig, axes = plt.subplots(nrows=4, ncols=3)
for ax in axes.flat:
    map_ax = Basemap(ax=ax)
    map_ax.drawcoastlines()
plt.show()

这篇关于底图子图出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:44