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

回答編集履歴

4

コード追加

2020/12/14 13:26

投稿

jbpb0
jbpb0

スコア7658

answer CHANGED
@@ -3,32 +3,35 @@
3
3
  普通の散布図の場合は、こんな感じで描けます
4
4
  (もっと簡単に描く方法があるかもしれませんが)
5
5
 
6
+ 【追記】pandasデータフレームからnumpy配列への変換を追加
6
7
  ```python
7
- # 架空のデータ
8
8
  import numpy as np
9
- x1 = range(24)
10
- y1 = np.random.rand(24)
9
+ import matplotlib.pyplot as plt
11
- x2 = range(24)
12
- y2 = np.random.rand(24)
13
- x3 = range(24)
14
- y3 = np.random.rand(24)
15
10
 
11
+ mcTrendAllnp = mcTrendAll.to_numpy()
16
12
 
13
+ xy1 = mcTrendAllnp[:, [0, 1]]
14
+ xy1 = xy1[~np.isnan(xy1).any(axis=1), :]
15
+
16
+ xy2 = mcTrendAllnp[:, [0, 2]]
17
+ xy2 = xy2[~np.isnan(xy2).any(axis=1), :]
18
+
19
+ xy3 = mcTrendAllnp[:, [0, 3]]
20
+ xy3 = xy3[~np.isnan(xy3).any(axis=1), :]
21
+
22
+
17
23
  num = 12 # 強調したい数字
18
24
 
19
- import numpy as np
20
- import matplotlib.pyplot as plt
21
-
22
25
  fig, ax = plt.subplots()
23
26
  ax.set_xticks(np.append(np.arange(0, 21, 5), num))
24
27
  colors = {str(num):'yellow'}
25
28
  weights = {str(num):'bold'}
26
29
  sizes = {str(num):16}
27
30
  ax.axvline(num, c='yellow', lw=0.5) # vertical lines
28
- ax.scatter(x1, y1, c='r', zorder=100)
31
+ ax.scatter(xy1[:, 0], xy1[:, 1], c='r', zorder=100)
29
- ax.scatter(x2, y2, c='g', zorder=100)
32
+ ax.scatter(xy2[:, 0], xy2[:, 1], c ='b', marker='^', zorder=100)
30
- ax.scatter(x3, y3, c='b', zorder=100)
33
+ ax.scatter(xy3[:, 0], xy3[:, 1], c ='g', marker='s', zorder=100)
31
- ax.grid()
34
+ ax.grid(color='lightgray', linestyle=':')
32
35
  ax.set_axisbelow(True)
33
36
  fig.canvas.draw()
34
37
  for xtic in ax.get_xticklabels():

3

コード追加

2020/12/14 13:26

投稿

jbpb0
jbpb0

スコア7658

answer CHANGED
@@ -6,8 +6,12 @@
6
6
  ```python
7
7
  # 架空のデータ
8
8
  import numpy as np
9
- x = range(24)
9
+ x1 = range(24)
10
- y = np.random.rand(24)
10
+ y1 = np.random.rand(24)
11
+ x2 = range(24)
12
+ y2 = np.random.rand(24)
13
+ x3 = range(24)
14
+ y3 = np.random.rand(24)
11
15
 
12
16
 
13
17
  num = 12 # 強調したい数字
@@ -17,11 +21,13 @@
17
21
 
18
22
  fig, ax = plt.subplots()
19
23
  ax.set_xticks(np.append(np.arange(0, 21, 5), num))
20
- colors = {str(num):'red'}
24
+ colors = {str(num):'yellow'}
21
25
  weights = {str(num):'bold'}
22
26
  sizes = {str(num):16}
23
- ax.axvline(num, c='red', lw=0.5) # vertical lines
27
+ ax.axvline(num, c='yellow', lw=0.5) # vertical lines
24
- ax.scatter(x, y, zorder=100)
28
+ ax.scatter(x1, y1, c='r', zorder=100)
29
+ ax.scatter(x2, y2, c='g', zorder=100)
30
+ ax.scatter(x3, y3, c='b', zorder=100)
25
31
  ax.grid()
26
32
  ax.set_axisbelow(True)
27
33
  fig.canvas.draw()

2

コード修正

2020/12/14 12:27

投稿

jbpb0
jbpb0

スコア7658

answer CHANGED
@@ -21,7 +21,7 @@
21
21
  weights = {str(num):'bold'}
22
22
  sizes = {str(num):16}
23
23
  ax.axvline(num, c='red', lw=0.5) # vertical lines
24
- ax.scatter(x, y)
24
+ ax.scatter(x, y, zorder=100)
25
25
  ax.grid()
26
26
  ax.set_axisbelow(True)
27
27
  fig.canvas.draw()

1

コード追加

2020/12/14 11:38

投稿

jbpb0
jbpb0

スコア7658

answer CHANGED
@@ -18,13 +18,18 @@
18
18
  fig, ax = plt.subplots()
19
19
  ax.set_xticks(np.append(np.arange(0, 21, 5), num))
20
20
  colors = {str(num):'red'}
21
+ weights = {str(num):'bold'}
22
+ sizes = {str(num):16}
21
23
  ax.axvline(num, c='red', lw=0.5) # vertical lines
22
24
  ax.scatter(x, y)
23
25
  ax.grid()
26
+ ax.set_axisbelow(True)
24
27
  fig.canvas.draw()
25
28
  for xtic in ax.get_xticklabels():
26
29
  if xtic.get_text() in colors.keys(): # Change color if exist else not
27
30
  xtic.set_color(colors[xtic.get_text()])
31
+ xtic.set_weight(weights[xtic.get_text()])
32
+ xtic.set_fontsize(sizes[xtic.get_text()])
28
33
 
29
34
  plt.show()
30
35
  ```