使用 python 在地理地图上插值温度数据,在边缘没有给出好的结果

问题描述 投票:0回答:0

我正在尝试在北极的立体地图上绘制一些关于温度的相关数据。数据来自该地区的不同站点。

我正在使用: 来自 scipy.interpolate:griddata 和来自 mpl_toolkits.basemap:底图。我的绘图部分代码如下所示: 我对格陵兰岛南部的样子不太满意。以及加拿大的一些地区和一般的边缘。谁能建议我可以做些什么来改进地图?

图:

import numpy as np
from scipy.interpolate import griddata
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import pandas as pd
from itertools import chain

def draw_map(m, scale=0.7):
    # draw a shaded-relief image
    # m.bluemarble(scale=scale)
    m.shadedrelief()
    
    
    # lats and longs are returned as a dictionary
    lats = m.drawparallels(np.linspace(-90, 90, 13))
    lons = m.drawmeridians(np.linspace(-180, 180, 13))

    # keys contain the plt.Line2D instances
    lat_lines = chain(*(tup[1][0] for tup in lats.items()))
    lon_lines = chain(*(tup[1][0] for tup in lons.items()))
    all_lines = chain(lat_lines, lon_lines)
    
    # cycle through these lines and set the desired style
    for line in all_lines:
        line.set(linestyle='-', alpha=0.3, color='w')

mydata = pd.read_csv("C:/Users/negar/negar/NewDirectory/cor_30.csv")

fig = plt.figure(figsize = (20, 20))
m = Basemap(projection='npstere',boundinglat=55,lon_0=0,resolution='l')
m.drawparallels(np.arange(-80.,81.,10.),  linewidth=0.4)
m.drawmeridians(np.arange(-180.,181.,10.),  linewidth=0.4)
x, y = m(mydata.iloc[:,5], mydata.iloc[:,4])
Jan_Feb = mydata.iloc[:, 6]
plt.scatter(x, y, c = Jan_Feb, cmap = "RdBu", marker = "o")
plt.colorbar(shrink = 0.65)
plt.title("Jan_Feb Correlation")
draw_map(m)
lllon = -180
lllat = 60
urlon = 180
urlat = 90
geo_df = mydata

# Make the edges:
lat = np.array(geo_df.iloc[:,4])
lat_all= np.append(lat, [lllat, urlat]) 
lon = np.array(geo_df.iloc[:,5])
lon_all = np.append(lon, [lllon, urlon])
data = np.array(geo_df.iloc[:,6])
# set up basemap chose projection!
m = Basemap(projection='npstere',boundinglat=55,lon_0=0,resolution='l')

# transform coordinates to map projection m
m_lon, m_lat = m(*(lon, lat))
m_on_all, m_lat_all = m(*(lon_all, lat_all))
# generate grid data
numcols, numrows = 500, 500
xi = np.linspace(m_lon_all.min(), m_lon_all.max(), numcols)
yi = np.linspace(m_lat_all.min(), m_lat_all.max(), numrows)
xi, yi = np.meshgrid(xi, yi)

# interpolate, there are better methods, especially if you have many datapoints
zi = griddata((m_lon,m_lat),data,(xi,yi),method='linear')

fig, ax = plt.subplots(figsize=(12, 12))

# draw map details
m.shadedrelief()
# m.drawmapboundary(fill_color = 'lightgreen', zorder = 1)

# Plot interpolated temperatures
m.contourf(xi, yi, zi, 500, cmap='RdBu', zorder = 2)

m.drawlsmask(ocean_color='skyblue', land_color=(0, 0, 0, 0), lakes=True, zorder = 3)

m.drawparallels(np.arange(-80.,81.,10.),  linewidth=0.4)
m.drawmeridians(np.arange(-180.,181.,10.),  linewidth=0.4)

c=plt.colorbar(shrink=0.75)
plt.clim(-1, 1) 
plt.title('Jan Feb Correlation')

plt.show()
python interpolation geospatial matplotlib-basemap
© www.soinside.com 2019 - 2024. All rights reserved.