質問するログイン新規登録

回答編集履歴

6

d

2018/12/23 17:04

投稿

tiitoi
tiitoi

スコア21962

answer CHANGED
@@ -12,8 +12,8 @@
12
12
 
13
13
  orient, speed = np.loadtxt('test.csv', delimiter=',').T
14
14
 
15
- orient = np.random.randint(0, 360, 100000)
15
+ #orient = np.random.randint(0, 360, 100000)
16
- speed = np.random.randint(0, 900, 100000)
16
+ #speed = np.random.randint(0, 900, 100000)
17
17
 
18
18
  x_edges = np.arange(0, 901, 100)
19
19
  y_edges = np.linspace(0, 360, 17)

5

d

2018/12/23 17:04

投稿

tiitoi
tiitoi

スコア21962

answer CHANGED
@@ -36,4 +36,49 @@
36
36
  ```
37
37
 
38
38
  numpy.histogram2d() の返り値 H の内容は以下の画像を見るとわかるかと思います。各要素は該当する個数を表しています。
39
+
39
- ![イメージ説明](d71c9a722a82895e8ac9ecec0b7d3b37.png)
40
+ ![イメージ説明](d71c9a722a82895e8ac9ecec0b7d3b37.png)
41
+
42
+ ## 追記
43
+
44
+ (元の角度 + 11.25) mod 360 としてから、ヒストグラムを作成すればよいです。mod をとるのは 元の角度が 350 の場合、350 + 11.25 = 361.25 となるので、361.25 mod 360 = 1.25 とするためです。
45
+
46
+ ```
47
+ ['-11.25 ~ 11.25',
48
+ '11.25 ~ 33.75',
49
+ '33.75 ~ 56.25',
50
+ '56.25 ~ 78.75',
51
+ '78.75 ~ 101.25',
52
+ '101.25 ~ 123.75',
53
+ '123.75 ~ 146.25',
54
+ '146.25 ~ 168.75',
55
+ '168.75 ~ 191.25',
56
+ '191.25 ~ 213.75',
57
+ '213.75 ~ 236.25',
58
+ '236.25 ~ 258.75',
59
+ '258.75 ~ 281.25',
60
+ '281.25 ~ 303.75',
61
+ '303.75 ~ 326.25',
62
+ '326.25 ~ 348.75']
63
+ ```
64
+
65
+
66
+
67
+ ```
68
+ ['0.0 ~ 22.5',
69
+ '22.5 ~ 45.0',
70
+ '45.0 ~ 67.5',
71
+ '67.5 ~ 90.0',
72
+ '90.0 ~ 112.5',
73
+ '112.5 ~ 135.0',
74
+ '135.0 ~ 157.5',
75
+ '157.5 ~ 180.0',
76
+ '180.0 ~ 202.5',
77
+ '202.5 ~ 225.0',
78
+ '225.0 ~ 247.5',
79
+ '247.5 ~ 270.0',
80
+ '270.0 ~ 292.5',
81
+ '292.5 ~ 315.0',
82
+ '315.0 ~ 337.5',
83
+ '337.5 ~ 360.0']
84
+ ```

4

d

2018/12/23 17:00

投稿

tiitoi
tiitoi

スコア21962

answer CHANGED
@@ -6,24 +6,29 @@
6
6
  なので、[numpy.histogram2d](https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.histogram2d.html#numpy.histogram2d) をお使いください。
7
7
 
8
8
  ```python
9
+ import matplotlib.pyplot as plt
9
10
  import numpy as np
10
- import matplotlib.pyplot as plt
11
+ import seaborn as sns # pip install seaborn
11
12
 
12
- data = np.loadtxt('test.csv', delimiter=',')
13
+ orient, speed = np.loadtxt('test.csv', delimiter=',').T
13
- # data = np.c_[np.random.randint(0, 360, 100000),
14
- # np.random.randint(0, 900, 100000)]
15
14
 
15
+ orient = np.random.randint(0, 360, 100000)
16
+ speed = np.random.randint(0, 900, 100000)
17
+
16
18
  x_edges = np.arange(0, 901, 100)
17
19
  y_edges = np.linspace(0, 360, 17)
18
- H = np.histogram2d(data[:, 0], data[:, 1],
20
+ H = np.histogram2d(np.mod(orient + 11.25, 360), speed,
19
21
  bins=(y_edges, x_edges))[0].astype(int)
20
22
  print(H.shape) # (16, 9)
21
23
 
22
- import seaborn as sns # pip install seaborn
23
24
  sns.set()
24
25
  # 目盛りのラベルを設定する。
25
- xlabels = ['{} ~ {}'.format(start, end) for start, end in zip(x_edges, x_edges[1:])]
26
+ xlabels = ['{} ~ {}'.format(start, end)
26
- ylabels = ['{} ~ {}'.format(start, end) for start, end in zip(y_edges, y_edges[1:])]
27
+ for start, end in zip(x_edges, x_edges[1:])]
28
+ ylabels = ['N', 'NNW', 'NW', 'WNW',
29
+ 'W', 'WSW', 'SW', 'SSW',
30
+ 'S', 'SSE', 'SE', 'ESE',
31
+ 'E', 'ENE', 'NE', 'NNE']
27
32
  # ヒートマップを作成する。
28
33
  sns.heatmap(H, annot=True, cmap='Reds', fmt='d',
29
34
  xticklabels=xlabels, yticklabels=ylabels, cbar=False)
@@ -31,5 +36,4 @@
31
36
  ```
32
37
 
33
38
  numpy.histogram2d() の返り値 H の内容は以下の画像を見るとわかるかと思います。各要素は該当する個数を表しています。
34
-
35
- ![イメージ説明](f67614c78801e7d89e7f30822cd1a79a.png)
39
+ ![イメージ説明](d71c9a722a82895e8ac9ecec0b7d3b37.png)

3

c

2018/12/23 16:53

投稿

tiitoi
tiitoi

スコア21962

answer CHANGED
@@ -30,20 +30,6 @@
30
30
  plt.show()
31
31
  ```
32
32
 
33
- 可視化する。
34
33
  numpy.histogram2d() の返り値 H の内容は以下の画像を見るとわかるかと思います。各要素は該当する個数を表しています。
35
34
 
36
-
37
- ```python
38
- import seaborn as sns # pip install seaborn
39
- sns.set()
40
- # 目盛りのラベルを設定する。
41
- xlabels = ['{} ~ {}'.format(start, end) for start, end in zip(velocity_edges, velocity_edges[1:])]
42
- ylabels = ['{} ~ {}'.format(start, end) for start, end in zip(orient_edges, orient_edges[1:])]
43
- # ヒートマップを作成する。
44
- sns.heatmap(H, annot=True, cmap='Reds', square=True,
45
- xticklabels=xlabels, yticklabels=ylabels)
46
- plt.show()
47
- ```
48
-
49
35
  ![イメージ説明](f67614c78801e7d89e7f30822cd1a79a.png)

2

d

2018/12/23 15:41

投稿

tiitoi
tiitoi

スコア21962

answer CHANGED
@@ -10,12 +10,24 @@
10
10
  import matplotlib.pyplot as plt
11
11
 
12
12
  data = np.loadtxt('test.csv', delimiter=',')
13
+ # data = np.c_[np.random.randint(0, 360, 100000),
14
+ # np.random.randint(0, 900, 100000)]
13
15
 
16
+ x_edges = np.arange(0, 901, 100)
14
- orient_edges = np.linspace(0, 360, 17)
17
+ y_edges = np.linspace(0, 360, 17)
18
+ H = np.histogram2d(data[:, 0], data[:, 1],
15
- velocity_edges = np.arange(0, 901, 100)
19
+ bins=(y_edges, x_edges))[0].astype(int)
16
- H, _, _ = np.histogram2d(
17
- data[:, 0], data[:, 1], bins=(orient_edges, velocity_edges))
18
20
  print(H.shape) # (16, 9)
21
+
22
+ import seaborn as sns # pip install seaborn
23
+ sns.set()
24
+ # 目盛りのラベルを設定する。
25
+ xlabels = ['{} ~ {}'.format(start, end) for start, end in zip(x_edges, x_edges[1:])]
26
+ ylabels = ['{} ~ {}'.format(start, end) for start, end in zip(y_edges, y_edges[1:])]
27
+ # ヒートマップを作成する。
28
+ sns.heatmap(H, annot=True, cmap='Reds', fmt='d',
29
+ xticklabels=xlabels, yticklabels=ylabels, cbar=False)
30
+ plt.show()
19
31
  ```
20
32
 
21
33
  可視化する。
@@ -34,4 +46,4 @@
34
46
  plt.show()
35
47
  ```
36
48
 
37
- ![イメージ説明](b75e61ea6adac2305988cc721db28253.png)
49
+ ![イメージ説明](f67614c78801e7d89e7f30822cd1a79a.png)

1

d

2018/12/23 15:41

投稿

tiitoi
tiitoi

スコア21962

answer CHANGED
@@ -1,7 +1,7 @@
1
1
  > ①角度を読み込みそれに対応する速度を16方位のリストに分割し、各方位のリストの個数から風向の頻度を求める
2
2
  > ②振り分けられた速度をさらに速度ごとに分割する作業を16方位分行い、各速度のリストの個数から風速の頻度を求める
3
3
 
4
- 1, 2 でやろうとしていることは、データを風0 ~ 360で16分割し、さらに0~900で9分割する2次元ヒストグラムの作成と考えることができます。
4
+ 1, 2 でやろうとしていることは、データを風0 ~ 360で16分割し、さらに風速0~900で9分割する2次元ヒストグラムの作成と考えることができます。
5
5
 
6
6
  なので、[numpy.histogram2d](https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.histogram2d.html#numpy.histogram2d) をお使いください。
7
7