print('Hello world!')
# 縦棒グラフを描いてみる(リストを使った方法)
import matplotlib.pyplot as plt
data = [90, 50, 55, 82] # dataリストは,要素が90, 50, 55, 82が保存されている
col = ["Mathematics", "English", "Japanese Language", "Information Study"] # colリストは,要素が文字列であり,"数学", "英語", "国語", "情報" が保存されている(文字列はダブルクォーテーションかシングルクォーテーションで囲う)
# 棒グラフを描画
plt.bar(col, data)
plt.title("Scores in 4 subjects") # グラフにタイトルを付ける
plt.show() # グラフの表示
# 他のグラフを描いてみる
##### 積上げ棒グラフの描画 #####
import numpy as np
# データの準備
y1 = np.array([30, 10, 40])
y2 = np.array([10, 50, 90])
# X軸のデータ
x = np.arange(len(y1))
# グラフの幅
w = 0.4
plt.figure(figsize = (10, 6))
p1 = plt.bar(x, y1, color = 'blue')
p2 = plt.bar(x, y2, bottom = y1, color='green') # bottom = y1と指定すると,y1のデータが下に積まれる
plt.xticks(x, ['Class A', 'Class B', 'Class C'])
plt.legend((p1[0], p2[0]), ('Math first', 'Math final'))
plt.show() # グラフの表示
##### 円グラフを描画 #####
labels = ['A', 'O', 'B', 'AB']
sizes = [40, 30, 20, 10]
colors = ['yellow', 'gold', 'cyan', 'pink'] # 円の色の指定
plt.figure(figsize = (15, 6))
plt.pie(sizes, labels = labels,
colors = colors, counterclock = False,
autopct = '%1.1f%%', startangle = 90)
plt.axis('equal') # 円を丸く描画
plt.show() # グラフの表示
To embed this project on your website, copy the following code and paste it into your website's HTML: