回答編集履歴

1

コード修正

2020/02/03 01:05

投稿

can110
can110

スコア38262

test CHANGED
@@ -6,16 +6,68 @@
6
6
 
7
7
  import matplotlib.pyplot as plt
8
8
 
9
+ import numpy as np
9
10
 
10
11
 
12
+
13
+ #df=pd.read_excel('地域出荷量.xlsx') の代わり
14
+
15
+ #
16
+
11
- df = pd.DataFrame({'地域':['北海道','東北','北陸','関東'], '出荷量':[50500,64600,13800,0]})
17
+ df = pd.DataFrame({ '地域':['北海道','東北','北陸','関東・東山','東海','近畿','中国','四国','九州','沖縄'],
18
+
19
+ '出荷量':[50500,64600,13800,0,85600,0,20200,19800,196800,3000]})
20
+
21
+
22
+
23
+
24
+
25
+ # 方法1:pandasで描画
26
+
27
+ #
12
28
 
13
29
  df.plot.bar(x='地域', rot=0)
14
30
 
15
31
  plt.show()
16
32
 
33
+
34
+
35
+ # 方法2:nmatplotlibで描画
36
+
17
- ```
37
+ #
38
+
39
+ plt.bar(df['地域'], df['出荷量'])
40
+
41
+ plt.show()
18
42
 
19
43
 
20
44
 
45
+ # 方法3:numpyにデータ変換してmatplotlibで描画
46
+
47
+ #
48
+
49
+ area=df['地域']
50
+
51
+ area = area.values.tolist()
52
+
53
+ area=np.array(area)
54
+
55
+
56
+
57
+ # 「出荷量」のデータをリスト化、さらにndarray化する
58
+
59
+ shipment=df['出荷量']
60
+
61
+ shipment=shipment.values.tolist()
62
+
63
+ shipment=np.array(shipment)
64
+
65
+
66
+
67
+ plt.bar(area,shipment)
68
+
69
+ plt.show()
70
+
71
+ ```
72
+
21
- ![イメージ説明](f5e4defda84821a369d9b26f4031e59b.png)
73
+ ![イメージ説明](f88205ae88c16efd6cc9fa22c8fbb112.png)