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

回答編集履歴

2

コメントを受けて回答を修正

2020/04/04 08:58

投稿

magichan
magichan

スコア15898

answer CHANGED
@@ -39,4 +39,41 @@
39
39
  plt.show()
40
40
  ```
41
41
 
42
- ![イメージ説明](74c708aecf9a71264a3654def5352a7b.png)
42
+ ![イメージ説明](74c708aecf9a71264a3654def5352a7b.png)
43
+
44
+ ---
45
+ **【追記】**
46
+ Y軸の値に3桁区切りをつけるには、(もう一つの質問で回答した)`FuncFormatter()` で変換するのが簡単です。
47
+ ```Python
48
+ plt.gca().get_yaxis().set_major_formatter(ticker.FuncFormatter(lambda v,p: f'{int(v):,d}'))
49
+ ```
50
+
51
+ 修正済みサンプルコード
52
+ ```
53
+ import pandas as pd
54
+ import numpy as np
55
+ import matplotlib.pyplot as plt
56
+ import matplotlib.ticker as ticker
57
+
58
+ N = 10
59
+ x = pd.date_range('2020/1/1 0:00', periods=N, freq='1d')
60
+ y = np.random.randint(10,100,N) * 1000
61
+ y2 = np.random.randint(10,100,N) * 1000
62
+ left = np.arange(N)
63
+
64
+ height1 = y
65
+ height2 = y2
66
+ labels = x.date
67
+
68
+ width = 0.4
69
+ plt.xticks(x, rotation=90)
70
+
71
+ plt.bar(left, height1, color='r', width=width, align='center',label='y')
72
+ plt.bar(left+width, height2, color='b', width=width, align='center',label='C')
73
+ plt.legend(loc = 'upper right')
74
+ plt.xticks(left + width/2, labels)
75
+ plt.gca().get_yaxis().set_major_formatter(ticker.FuncFormatter(lambda v,p: f'{int(v):,d}'))
76
+ plt.tight_layout()
77
+ plt.show()
78
+ ```
79
+ ![イメージ説明](762297fdd109cab4820f4886559461be.png)

1

サンプルに余分なinportがあったので削除

2020/04/04 08:58

投稿

magichan
magichan

スコア15898

answer CHANGED
@@ -15,7 +15,6 @@
15
15
  import pandas as pd
16
16
  import numpy as np
17
17
  import matplotlib.pyplot as plt
18
- import matplotlib.dates as mdates
19
18
 
20
19
  # 質問にデータが提示されていないので適当に作成
21
20
  N = 10