Skip to content

Commit 5f11837

Browse files
committedDec 27, 2018
1st Release
0 parents  commit 5f11837

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed
 

‎GraphPlot.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
3+
#---------------------------------------------------------------------
4+
# ライブラリの読み込み
5+
#---------------------------------------------------------------------
6+
import pandas as pd
7+
import numpy as np
8+
import matplotlib as mpl
9+
import matplotlib.pyplot as plt
10+
11+
12+
#---------------------------------------------------------------------
13+
# 横棒グラフの表示
14+
#---------------------------------------------------------------------
15+
def PlotBarGraph():
16+
17+
# 擬似データ作成
18+
values = [3, 12, 5, 18, 45]
19+
series = ('A', 'B', 'C', 'D', 'E')
20+
y_pos = np.arange(len(series)) # 通番を格納した配列を作成 [0,1,2,...,len(series)]
21+
22+
# グラフタイトルの設定
23+
plt.title("TITLE")
24+
25+
# 横軸の設定(値)
26+
plt.barh(y_pos, values)
27+
plt.xlabel('X')
28+
29+
# 縦軸の設定(系列名)
30+
plt.yticks(y_pos, series)
31+
plt.ylabel('Y')
32+
33+
# グラフを表示する
34+
plt.show()
35+
36+
37+
#---------------------------------------------------------------------
38+
# Entry Point
39+
#---------------------------------------------------------------------
40+
41+
# CSVデータの読み込み(統計データ)
42+
df = pd.read_csv('StatData.csv', sep=',')
43+
#print(df.head())
44+
45+
# グラフのスタイル設定 (Gnuplot & Meiryo)
46+
plt.style.use('ggplot')
47+
font = {'family' : 'Miryo UI'}
48+
mpl.rc('font', **font)
49+
df.plot(y=['Male', 'Female', 'Total'], alpha=0.5)
50+
51+
# グラフのラベル設定
52+
plt.title("Town")
53+
plt.ylabel('Population')
54+
plt.xlabel('Survey Time')
55+
56+
# グラフの表示
57+
plt.show()
58+
59+
#---------------------------------------------------------------------
60+
# Reference
61+
#---------------------------------------------------------------------
62+
#
63+
# [01] pyplot — Matplotlib 2.0.2 documentation
64+
# https://matplotlib.org/api/pyplot_api.html
65+
#
66+
# [02] Numpy developer guide
67+
# https://docs.scipy.org/doc/numpy/dev/
68+
#
69+
# [03] matplotlib入門 / りんごがでている
70+
# http://bicycle1885.hatenablog.com/entry/2014/02/14/023734
71+
#
72+
# [02] Horizontal barplot / The Python Graph Gallary
73+
# https://python-graph-gallery.com/2-horizontal-barplot/
74+
#
75+
#
76+
#---------------------------------------------------------------------
77+
# Memo
78+
#---------------------------------------------------------------------
79+
#
80+
#

‎GraphPlot2.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
# データ設定
6+
7+
# 関数型
8+
x = np.arange(-np.pi, np.pi, np.pi/100)
9+
plt.plot(x, np.sin(x)*10)
10+
plt.plot(x, np.cos(x)*20)
11+
12+
# 散布図型
13+
plt.plot([-1,0,1],[10,0,-10])
14+
plt.plot([-1,0,1],[20,0,-20])
15+
16+
# ヒストグラム型
17+
x2 = np.random.randn(1000)
18+
plt.hist(x2-0.5, bins=10, alpha=0.3, histtype='stepfilled', color='r')
19+
20+
# グラフ表示設定
21+
plt.title('Title')
22+
plt.xlabel('Y')
23+
plt.ylabel('X')
24+
plt.legend(['Graph1','Graph2','Graph3','Graph4','Graph5'])
25+
plt.grid(True)
26+
27+
# グラフ表示実行
28+
plt.savefig('GraphPlot.png')
29+
30+
# グラフの画面表示
31+
plt.show()
32+
33+
#---------------------------------------------------------------------
34+
# End

‎StatData.csv

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Time,Male,Female,Total
2+
昭和47年,"6469","6767","13236"
3+
昭和48年,"6585","6865","13450"
4+
昭和49年,"6828","7095","13923"
5+
昭和50年,"7155","7436","14591"
6+
昭和51年,"7445","7675","15120"
7+
昭和52年,"7650","7879","15529"
8+
昭和53年,"7824","8097","15921"
9+
昭和54年,"8233","8417","16650"
10+
昭和55年,"8671","8849","17520"
11+
昭和56年,"9015","9163","18178"
12+
昭和57年,"9251","9439","18690"
13+
昭和58年,"9452","9661","19113"
14+
昭和59年,"9739","9971","19710"
15+
昭和60年,"10002","10238","20240"
16+
昭和61年,"10279","10542","20821"
17+
昭和62年,"10640","10854","21494"
18+
昭和63年,"10946","11176","22122"
19+
平成1年,"11381","11543","22924"
20+
平成2年,"11793","11905","23698"
21+
平成3年,"12558","12600","25158"
22+
平成4年,"13748","13720","27468"
23+
平成5年,"14745","14805","29550"
24+
平成6年,"15741","15815","31556"
25+
平成7年,"16623","16611","33234"
26+
平成8年,"17210","17182","34392"
27+
平成9年,"17684","17827","35511"
28+
平成10年,"18076","18247","36323"
29+
平成11年,"18350","18523","36873"
30+
平成12年,"18547","18682","37229"
31+
平成13年,"18699","18845","37544"
32+
平成14年,"18739","18908","37647"
33+
平成15年,"18797","19053","37850"
34+
平成16年,"18952","19264","38216"
35+
平成17年,"18978","19276","38254"
36+
平成18年,"18970","19278","38248"
37+
平成19年,"18941","19138","38079"
38+
平成20年,"18870","19078","37948"
39+
平成21年,"18793","19071","37864"
40+
平成22年,"18761","19017","37778"
41+
平成23年,"18709","18838","37547"
42+
平成24年,"18565","18847","37412"
43+
平成25年,"18486","18712","37198"
44+
平成26年,"18404","18697","37101"
45+
平成27年,"18313","18561","36874"
46+
平成28年,"18213","18583","36796"

0 commit comments

Comments
 (0)
Please sign in to comment.