我有以下地图,我根据边缘的纬度和经度在其上添加了瓷砖。1-如何获得 dpi 中的坐标。(我想这取决于我在 savefig 函数中定义的 dpi)。有什么函数可以给我转换后的值吗?我想把这个图放在 html 标记中,并且需要将平铺坐标放入标记中以使其可点击并连接到链接。
2-如何使用 oceanmask() (或任何其他解决方案,如果有)来切出覆盖海洋的瓷砖部分?
这里,是代码:
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)