gpt4 book ai didi

python - 为什么六边形网格在极坐标立体投影中会变形

转载 作者:行者123 更新时间:2023-12-01 08:27:46 26 4
gpt4 key购买 nike

我试图理解为什么北极或南极立体投影中的六边形图显示被压扁的六边形,即使网格的面积是正方形并且投影的面积大致相等。

我已经尝试使用 basemap 进行北极和南极立体投影。

import numpy as np
from numpy.random import uniform
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

fig = plt.figure(figsize=(12,10)) # width, height in inches
ax =fig.add_axes([-0.02,0.1,0.74,0.74])

m = Basemap(epsg='3413',lon_0=0.,resolution='l',width=6000000,height=6000000)

m.drawcoastlines()

m.drawmapscale(0.,90.,0.,90.,1000)

npts=2000
lats = uniform(60.,80.,size=npts)
lons = uniform(0.,360.,size=npts)
data = uniform(0.,4800.,size=npts)

x,y=m(lons, lats)

thiscmap=plt.cm.get_cmap('viridis')

p=m.hexbin(x,y,C=data,gridsize=[10,10],cmap=thiscmap)

plt.show()

plot output

最佳答案

我不知道为什么你会得到被压扁的六边形。但是您可以通过设置适当的gridsize值来调整六边形形状。在这里我修改了你的代码并获得更好的情节。

import numpy as np
from numpy.random import uniform
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

fig = plt.figure(figsize=(12,10)) # width, height in inches
ax =fig.add_axes([-0.02, 0.1, 0.74, 0.74])

# North polar stereographic projection epsg='3413'; ***large areal distortion***
#m = Basemap(epsg='3413', lon_0=0., resolution='c', width=6000000, height=6000000)

# 'laea': Lambert Azimuthal Equal Area
# Thematic mapping with ground surface data should be plotted on 'equal-area' projection
m = Basemap(projection='laea', lon_0=0., lat_0=90, resolution='l', width=6000000, height=6000000)

m.drawcoastlines(linewidth=0.5)

m.drawmapscale(0.,90.,0.,90.,1000) # 1000 km?

npts = 2000
lats = uniform(60.,80.,size=npts) # not cover N pole
lons = uniform(0.,360.,size=npts) # around W to E
data = uniform(0.,4800.,size=npts)

x,y = m(lons, lats)

thiscmap = plt.cm.get_cmap('viridis')

# To get 'rounded' hexagons, gridsize should be specified appropriately
# need some trial and error to get them right
#p=m.hexbin(x, y, C=data, gridsize=[10,10], cmap=thiscmap) # original code
m.hexbin(x, y, C=data, gridsize=[16,11], cmap=thiscmap) # better

plt.colorbar() # useful on thematic map

plt.show()

您使用的投影(epsg:3413)是立体投影,具有较大的面积失真。在这种情况下,更适合专题 map 的投影是兰伯特方位角等面积

结果图:

enter image description here

关于python - 为什么六边形网格在极坐标立体投影中会变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54115612/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com