2017-07-03 7 views
0

私は、ベースマップを使用して熱/強度マップを作成しようとしています。私の入力は、その時点でのラット、lons、および強度のセットです。データセットは次のようになります。pcolormeshへの入力フォーマット

各インデックスで、latとlonは正しいセンサーの読みに対応します。私のコードは次のようになります:

fig = plt.figure(figsize=(10, 8)) 


# Set title 
fig.suptitle("Intensities {} {}".format(start_time, stop_time)) 


# US Centered Map 
map_axis = fig.add_subplot(111) 
map = Basemap(
    ax = map_axis, 
    lat_0 = 40, lon_0 = -95, 
    width = 6500e3, height = 6500e3, 
    projection = 'stere', 
    resolution = 'l' 
) 
map.drawcoastlines() 


lats = ... 
lons = ... 
intn = ... 


# Convert coordinates 
lons, lats = map(lons, lats) 


LONS, LATS = np.meshgrid(lons, lats) 
map.pcolormesh(
    LONS, LATS, 
    intn, 
    vmin = 0, vmax = 100 
) 


fig.savefig(file_name) 
plt.close(fig) 

このコードは決して完成しません。私は正常にBasemapをプロットしました。 pcolormeshは失敗しているものです。プログラムがこのエラーでクラッシュします。

$ ./plot_intensities.py 
    Running 2013-04-10 00:02:30 2013-04-10 00:02:45 
    Traceback (most recent call last): 
     File "./plot_intensities.py", line 151, in <module> 
     make_maps(samples) 
     File "./plot_intensities.py", line 144, in make_maps 
     make_map(bin_samples, start, walk) 
     File "./plot_intensities.py", line 117, in make_map 
     vmin = 0, vmax = 100 
     File "/usr/lib/python3/dist-packages/mpl_toolkits/basemap/__init__.py", line 521, in with_transform 
     return plotfunc(self,x,y,data,*args,**kwargs) 
     File "/usr/lib/python3/dist-packages/mpl_toolkits/basemap/__init__.py", line 3418, in pcolormesh 
     ret = ax.pcolormesh(x,y,data,**kwargs) 
     File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 1814, in inner 
     return func(ax, *args, **kwargs) 
     File "/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py", line 5395, in pcolormesh 
     X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch) 
     File "/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py", line 4995, in _pcolorargs 
     numRows, numCols = C.shape 
    ValueError: not enough values to unpack (expected 2, got 1) 

私は私のデータは、第三引数intnが正しくフォーマットされていないことを理解しています。私はどのように私はそのリストを形成する必要があるかに関するドキュメントを見つけることができません。正しい形にするにはどうすればいいですか?

ありがとうございました。

答えて

2

ご存じのように、pcolormeshは、2次元配列の疑似カラープロットを作成することによって四辺形メッシュをプロットするために使用されます。エラーの詳細は、numRows, numCols = C.shapeではCが2次元配列であるとしますが、CValueError: not enough values to unpack (expected 2, got 1)から1次元配列のように見えます。あなたが導入したデータセットは、私には対角線上の強度値(lat == lon)しかないようです。カラーメッシュを取得するには、少なくとも強度データを2次元配列に拡張し、何らかの形で欠損値を埋め込む必要があります。たとえば、次のように

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

fig = plt.figure(figsize=(10, 8)) 
# Set title 
fig.suptitle("Intensities {} {}".format('start_time', 'stop_time')) 
# US Centered Map 
map_axis = fig.add_subplot(111) 
map = Basemap(
    ax = map_axis, 
    lat_0 = 40, lon_0 = -95, 
    width = 6500e3, height = 6500e3, 
    projection = 'stere', 
    resolution = 'l' 
) 
map.drawcoastlines() 

# Tried my best to simulate your data example. Don't be surprise if the result is ugly ... 
nstep = 1 
lats = np.arange(map.latmin, map.latmax, nstep) 
lons = np.arange(map.lonmin, map.lonmax, nstep) 
l = min(len(lats), len(lons)) 
lats = lats[:l] 
lons = lons[:l] 
intn = np.random.randint(0, 100, size=l) 

# Convert coordinates 
lons, lats = map(lons, lats) 
LONS, LATS = np.meshgrid(lons, lats) 

# The following 3 lines are just an example of the minimum you got to do before it works. 
intn_array = np.zeros(LONS.shape) 
for i in range(l): 
    intn_array[i, i] = intn[i] 
intn = intn_array 

map.pcolormesh(
    LONS, LATS, 
    intn_array, 
    vmin = 0, vmax = 100 
) 

plt.show() 

enter image description here

関連する問題