绘制Python 2.7底图上的等高线图

时间:2016-03-13 20:35:48

标签: python numpy matplotlib scipy matplotlib-basemap

我在python中有关于Matplotlib和Basemap的问题。我试图列出纬度,经度和温度,并在等高线图上绘制它们。当我为阿拉斯加提供数据时,我取得了相对的成功。它绘制我的数据没问题。当我尝试为阿拉巴马州输入数据时,它输出了一个完全随机的地图,里面装满了一堆垃圾数据点。我认为这可能是地图投影的一个问题,因为我提供了阿拉斯加数据,这些数据为我提供了阿拉巴马数据的工作地图,该地图为我提供了随机数据。可能是坐标的差异扭曲了温度值。我不太确定。

谢谢, 斯科特

以下是Alabama数据的示例(第一栏:ICAO,第二栏:lat,第三栏:lon,第四栏:temp):

K8A0,34.14,-86.15,64

KALX,32.55,-85.58,65

K79J,31.19,-86.24,75

KANB,33.35,-85.51,69

import urllib2
from urllib2 import urlopen
import cookielib
from cookielib import CookieJar
import time
from Tkinter import *
import numpy as np
import pandas as pd
from matplotlib.mlab import griddata
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from scipy import interpolate
import scipy
from matplotlib.colors import Normalize


FN = '/Users/scottreinhardt/Desktop/airportcodetext1.txt'
data = np.genfromtxt(FN,dtype=None,names=["ICAO","Lat","Lon","Temp"],skip_header=1,delimiter=',')
m = Basemap(projection = 'cyl',llcrnrlon = -73.5, llcrnrlat = 41, urcrnrlon = -81, urcrnrlat = 30, resolution='h')
        # data from http://water.weather.gov/precip/


        # create polar stereographic Basemap instance.
plt.figure(num=None, figsize=(25, 25), dpi=25,edgecolor='k')

xs = np.array(data["Lon"])
ys = np.array(data["Lat"])
z = np.array(data["Temp"])

        #x = x + np.random.normal(scale=1e-8, size=x.shape)
        #y = y + np.random.normal(scale=1e-8, size=y.shape)


        #numcols, numrows = 300, 300
xi = np.linspace(data["Lat"].min(), data["Lat"].max(), 150)
yi = np.linspace(data["Lon"].min(), data["Lon"].max(), 150)
xi, yi = np.meshgrid(xi, yi)
        # Set up a regular grid of interpolation points
#xi, yi = np.linspace(xs.min(), xs.max(), 500), np.linspace(ys.min(), ys.max(), 500)
#xi, yi = np.meshgrid(xi, yi)
        # Interpolate
rbf = scipy.interpolate.Rbf(data["Lat"], data["Lon"], data["Temp"], function='linear')
zi = rbf(xi, yi)
plt.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower',
extent=[xs.min(), xs.max(), ys.min(), ys.max()])
plt.colorbar()
plt.show()

0 个答案:

没有答案