【问题标题】:Can't get my data plotted as countour map on basemap无法将我的数据绘制为底图上的等高线图
【发布时间】:2017-10-09 10:13:06
【问题描述】:

我正在尝试绘制全球气体排放图。但是,我似乎无法在放大器上绘制我的数据 (NH3idx)。我不知道从经纬度坐标到地图投影坐标的转换是否错误,或者我无法读取我想要绘制的数据。

import numpy as np
import pylab as plt
import math
from mpl_toolkits.basemap import Basemap
import csv


dlat = 0.1
dlon = 0.1
nlat = 1800
nlon = 3600

longrid = -180 + np.arange(nlon) * dlon
latgrid = -90 + np.arange(nlat) * dlat

NH3idx = np.zeros([nlon,nlat])

with open ('NH3_2008.txt') as csvfile:
    plots = csv.reader(csvfile, delimiter=';')
    for row in plots:
        inlon = float(row[1])
        inlat = float(row[0])
        lonidx = int(abs(inlon + 180)/dlon)
        latidx = int(abs(inlat +90)/dlat)
        NH3idx[lonidx,latidx] = float(row[2])

plt.figure(figsize=(20,10))
m = Basemap(projection='cyl', llcrnrlat=-90,urcrnrlat=90,\
        llcrnrlon=-180,urcrnrlon=180,resolution='l')

y,x = np.meshgrid(latgrid, longrid)


m.drawcoastlines()
m.drawmeridians(np.arange(-180.,180.,20.))
m.drawparallels(np.arange(-90.,90.,20.))
m.drawmapboundary(fill_color='white')    

plt.contourf(x,y,NH3idx)
plt.colorbar()

plt.show()

我的数据如下所示:

the columns are lat, lon, emissions

【问题讨论】:

    标签: python matplotlib matplotlib-basemap contourf


    【解决方案1】:

    您需要先将坐标转换为底图坐标

    X,Y = m(x,y)
    

    那么你可能想使用底图计数功能

    m.contourf(X,Y,NH3idx)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-27
      • 2015-09-12
      • 1970-01-01
      • 2023-02-04
      • 2021-05-19
      • 2015-01-08
      相关资源
      最近更新 更多