棒グラフ
import matplotlib.pyplot as plt
from matplotlib import style
# 棒グラフ
style.use("ggplot")
x = [1,3,5]
y = [4,5,1]
x2 = [2,4,6]
y2 = [6,3,2]
plt.bar(x,y, label='xy', color="green")
plt.bar(x2,y2, label='x2y2', color="blue")
plt.title("bar_chart")
plt.xlabel("X")
plt.ylabel("Y")
plt.legend()
plt.grid(True, color='blue')
plt.show()
ヒストグラム
import matplotlib.pyplot as plt
# ヒストグラム
x = [1,3,5,7,4,5,6,9]
y = [1,2,3,4,5,6,7,8]
plt.hist(x,y, histtype='bar', rwidth=0.8)
plt.title("Historgram")
plt.xlabel("X")
plt.ylabel("Y")
plt.legend()
plt.show()
折れ線
import matplotlib.pyplot as plt
from matplotlib import style
# 折れ線
style.use("ggplot")
x = [1,2,3]
y = [4,5,1]
x2 = [1,2,3]
y2 = [6,3,2]
plt.plot(x,y, 'g', label='xy', linewidth=5)
plt.plot(x2,y2, 'r', label='x2y2', linewidth=5)
plt.title("line_chart")
plt.xlabel("X")
plt.ylabel("Y")
plt.legend()
plt.grid(True, color='blue')
plt.show()
散布図
import matplotlib.pyplot as plt
from matplotlib import style
# 散布図
x = [1,3,5,7,4,5,6,9]
y = [1,2,3,4,5,6,7,8]
plt.scatter(x,y, label='position', color='g', s=25, marker='o')
plt.title("scatter plot")
plt.xlabel("X")
plt.ylabel("Y")
plt.legend()
plt.show()
積み上げ折れ線グラフ
import matplotlib.pyplot as plt
# 積み上げ折れ線グラフ
days = [1,2,3,4,5]
study = [7,8,6,11,7]
eat = [2,3,4,3,2]
work = [7,8,7,2,2]
play = [8,5,7,8,13]
plt.plot([], [], color='m', label='S', linewidth=5)
plt.plot([], [], color='c', label='E', linewidth=5)
plt.plot([], [], color='r', label='W', linewidth=5)
plt.plot([], [], color='k', label='P', linewidth=5)
plt.stackplot(days, study, eat, work, play, colors=['m', 'c', 'r', 'k'])
plt.xlabel("Days")
plt.ylabel("Action")
plt.title("My workdays")
plt.legend()
plt.show()