以像素为单位获取切片的坐标,使用maskocean切割地图上的切片。底图

时间:2013-07-12 09:40:02

标签: python matplotlib maps matplotlib-basemap

我有以下地图,我根据边缘的纬度和经度在其上添加了瓷砖。 1-如何在dpi中获得坐标。 (我想这取决于我在savefig函数中定义的dpi)。有什么功能可以给我转换后的值吗?我想把这个数字放在html标签里面,并且需要将标尺坐标放入标签中以使它们可以点击并连接到链接。

2-如何使用oceanmask()(或任何其他解决方案,如果有的话)来切割覆盖海洋的瓷砖部分?

tiled map of the world. I want to cut out the parts on the ocean, and use it in a web page in <map> and <area> tags

这里是代码:

from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon

def draw_screen_poly( lats, lons, m, thecolor):
    x, y = m( lons, lats )
    xy = zip(x,y)
    poly = Polygon( xy, facecolor=thecolor, alpha=0.4 )
    plt.gca().add_patch(poly)

lats =[[-28  ,-11, -11,-28], [-45 ,-28, -28,-45] ,[-20  ,12, 12, -20], [-56  ,-20, -20,-56] , [10  , 30, 30, 10 ],
[30  , 60, 60, 30 ], [30  , 50, 50, 30 ], [30  , 50, 50, 30 ], [60  , 72, 72, 60 ], [50  , 85, 85, 50 ],
[30  , 48, 48, 30 ], [48  , 75, 75, 48 ], [-12  , 18,  18,-12] ,[-12  , 18,  18,-12] ,[-35  , -12,-12,-35] ,
[18  , 30, 30, 18 ], [-11  , 20,  20,-11], [20  ,50, 50, 20 ], [5   , 30, 30, 5  ], [30  , 50,  50,30],
[30  , 50,  50, 30], [50  , 75,  75, 50] ]

lons= [[110, 110,  155, 155], [110, 110,  155, 155], [-82, -82,  -34, -34], [-76, -76,  -40, -40], [-116,-116, -83, -83],
[-130,-130, -103, -103], [-103, -103, -85, -85], [-85, -85,  -60, -60], [-170,-170, -103, -103], [-103,-103, -10, -10],
[-10, -10,  40, 40], [-10, -10,  40, 40], [-20, -20,  22, 22], [22,  22,   52, 52], [-10, -10,  52, 52], [-20, -20,  65, 65],
[95,  95,   155, 155], [100, 100,  145, 145], [65,  65,   100, 100], [40,  40,   75, 75], [75,  75,   100, 100],[40,  40,   180, 180]]

colors = ['#FFF700', '#9A00D7', '#65FF00', '#FF0000', '#0057C4', '#FFA700', '#3600FF', '#D0FF00', '#DD008B', '#0BBD39', '#FF3D00',
           '#0014FE', '#FFDE00', '#FF7E79', '#011893', 'red', 'green', 'blue', 'cyan', 'magenta', 'yellow', '#008F51']

m = Basemap(projection='cyl',lon_0=0)
m.drawcoastlines(linewidth=.5)
m.drawmapboundary(fill_color='#BDE7FF')

m.fillcontinents(color='white',lake_color='aqua')

for lat, lon, color in zip(lats, lons, colors):
    draw_screen_poly( lat, lon, m, color)

plt.savefig('themap.png', dpi=150, edgecolor='red', format='png', bbox_inches='tight', pad_inches=.1)

0 个答案:

没有答案