0

同じ長さの1D配列が3つあります。これらは:

  1. 温度(F)
  2. 風速
  3. 風向き

温度と風速にはすべてフロート値があり、風向には「南」、「北」、「北東」、「西」などの文字列値があります。次に、これらの配列を使用して3Dスキャッタプロットを作成します。可能な方法(風向配列には文字列値があるため)?このシナリオにいくつかのロジックを適用できますか?

4

3 に答える 3

4

次のように、x軸(東方向)と風向の間の角度を定義する辞書の角度を定義できます。

angles = {'East': 0., 'North': math.pi/2., 'West': math.pi, 'South': 3.*math.pi/2.}

次に、次の例のように、x(東)およびy(北)方向の速度を計算できます。

import math

angles = {'East': 0., 'North': math.pi/2., 'West': math.pi, 'South': 3.*math.pi/2.}

directions = ['East', 'North', 'West', 'South']
vtot = [1.5, 2., 0.5, 3.]
Temperature = [230., 250. , 200., 198.] # K

vx = [vtot[i]*math.cos(angles[directions[i]]) for i in range(len(directions))] # velocity in x-direction (East)
vy = [vtot[i]*math.sin(angles[directions[i]]) for i in range(len(directions))] # velocity in y-direction (North)

print (vx)
print (vy)

次に、、、およびmatplotlibの任意の3Dプロットでプロットvxできます。vyTemperature

于 2012-11-22T09:08:28.547 に答える
2

@pwagnerのように、私は極座標プロットに行きますが、3Dプロットに行きます。基本的に、以下の例のように、風を極度に再マッピングすることができます。

angles = {'east':0, 'northeast':np.pi/4, 'north':np.pi/2, 'northwest':3*np.pi/4,
          'west':np.pi, 'southwest':5*np.pi/4, 'south':3*np.pi/2, 'southeast':7*np.pi/4}
wind_angle = np.array([angles[i] for i in wind])

これにより、風向がわかります。次に、(風、速度)座標をデカルトに変換し、3D散布図でプロットできます。以下に示す完全な例を使用して、カラーマップで温度をコーディングすることもできます。

import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

wind_dirs = ['east', 'northeast', 'north', 'northwest',
             'west', 'southwest', 'south', 'southeast']
# data
speed = np.random.uniform(0,1.25,100)
temp = np.random.uniform(-10,20,100)
wind = [wind_dirs[i] for i in np.random.randint(8, size=100)]

#transform data to cartesian
angles = {'east':0, 'northeast':np.pi/4, 'north':np.pi/2, 'northwest':3*np.pi/4,
          'west':np.pi, 'southwest':5*np.pi/4, 'south':3*np.pi/2, 'southeast':7*np.pi/4}
wind_angle = np.array([angles[i] for i in wind])
X,Y = speed*np.cos(wind_angle),speed*np.sin(wind_angle)

ax.scatter3D(X, Y, temp, c = temp, cmap=cm.bwr)
ax.set_zlabel('Temp')
plt.show()

これにより、次の場所で回転およびズームできる優れたグラフが作成されます。

ここに画像の説明を入力してください

于 2012-11-22T09:09:03.840 に答える
0

この質問を読んでいるとき、私は極座標プロット(当然のことながら風向の場合)と色としてエンコードされた温度について考える必要があります。クイック検索により、既存のmatplotlibの例が表示されました。例を書き直すと、次のようになります。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

N = 150
r = 2.0 * np.random.randn(N)
theta = 2.0 * np.pi * np.random.randn(N)
area = 10.0 * r**2.0 * np.random.randn(N)
colors = theta
ax = plt.subplot(111, polar=True)
c = plt.scatter(theta, r, c=colors, cmap=cm.hsv)
c.set_alpha(0.75)

ticklocs = ax.xaxis.get_ticklocs()
ax.xaxis.set_ticklabels([chr(number + 65) for number in range(len(ticklocs))])

plt.show()

この例をさらにニーズに合わせて採用していただければ幸いです。

于 2012-11-22T08:34:53.870 に答える