Python底图:使用shadedrelief,bluemarble或etopo(错误的经度格式?)时出错 [英] Python Basemap: Error using shadedrelief, bluemarble or etopo (false longitude format?)

查看:459
本文介绍了Python底图:使用shadedrelief,bluemarble或etopo(错误的经度格式?)时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制以太平洋为中心的南半球地图,并用python matplotlib底图在上面绘制一些东西.

I want to plot a map of the southern hemisphere centered on the pacific with some stuff drawn onto it with python matplotlib basemap.

一切正常,除非我尝试使用底图例程shadedrelief,bluemarble或etopo绘制背景图像.代码(没有我想在地图上绘制的东西)看起来像这样:

Everything works fine unless I try to draw a background image with the basemap routines shadedrelief, bluemarble or etopo. The code (without the stuff i want to draw onto the map) looks like this:

import numpy as np
from mpl_toolkits.basemap import Basemap
from matplotlib.backends.backend_pdf import PdfPages

latmin = -72.5
latmax = 40.
lonmin = 60.
lonmax = 370.

pp = PdfPages('datamap.pdf')

m = Basemap(projection='merc', llcrnrlat=latmin, urcrnrlat=latmax, llcrnrlon=lonmin, urcrnrlon=lonmax, resolution="c")

m.drawcoastlines(linewidth=0.25)
#m.shadedrelief()

pp.savefig()
pp.close()

取消对m.shadedrelief()的注释时,将得到以下内容:

When I uncomment the m.shadedrelief() I get the following:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/xyz/datamap.py in <module>()
     32
---> 33 m.shadedrelief()
     34 

/usr/local/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in shadedrelief(self, ax, scale, **kwargs)
   3997             return self.warpimage(image='shadedrelief',ax=ax,scale=scale,**kwargs)
   3998         else:
-> 3999             return self.warpimage(image='shadedrelief',scale=scale,**kwargs)
   4000 
   4001     def etopo(self,ax=None,scale=None,**kwargs):

/usr/local/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in warpimage(self, image, scale, **kwargs)
   4115                 # any range of longitudes may be plotted on a world map.
   4116                 self._bm_lons = \
-> 4117                 np.concatenate((self._bm_lons,self._bm_lons+360),1)
   4118                 self._bm_rgba = \
   4119                 np.concatenate((self._bm_rgba,self._bm_rgba),1)
IndexError: axis 1 out of bounds [0, 1)

当我选择(用于测试目的)较小的地图(经度也不大于180度)时,所有地图(包括阴影浮雕)都可以正常工作.这使我得出一个假设,即经度格式的内容在这里不起作用.我尝试了一些方法,但似乎无法找到一种方法来解决这个问题,同时仍然绘制相同的地图部分

When I choose (for test purposes) way smaller maps which also dont have longitude larger than 180 degree everything (including shadedrelief) works fine. This leads me to the assumption that something with the format of the longitude is not working here. I tried some things but i cant seem to find a way how to solve this while still plotting the same map section

您是否知道如何在地图背景中绘制阴影?

Do you have any idea how i could draw a shadedrelief in the background of my map?

最好

xilian

推荐答案

底图/ init 代码似乎存在错误.实际上,如果您查看github上的最新版本[请参阅

It seems there was a bug in the basemap/init code. In fact, if you look at the latest version on github [see https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/init.py#L4139 and how it is different from line 4117 of your error] you will find out that the bug has been solved already. This means you can either do:

# np.concatenate((self._bm_lons,self._bm_lons+360),1)
np.concatenate((self._bm_lons,self._bm_lons+360))

init .py代码中

或获取较新版本的底图.两者中的任何一个都可以解决您的问题.

in the init.py code or get a newer version of basemap. Any of the two will solve your problem.

这篇关于Python底图:使用shadedrelief,bluemarble或etopo(错误的经度格式?)时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆