Pythonトレーニング


4.3-3 グラフの描画

①折れ線グラフ

import matplotlib.pyplot as plt
x_data = [1, 2, 3, 4, 5]
y_data = [20, 50, 30, 40, 10]
plt.plot(x_data, y_data)
plt.show()

②棒グラフ

import matplotlib.pyplot as plt
x_data = range(0, 5)
y_data = [20, 50, 30, 40, 10]
x_label = ["A", "B", "C", "D", "E"]
plt.bar(x_data, y_data, tick_label=x_label)
plt.show()

③散布図

import matplotlib.pyplot as plt
x_data = [1, 2, 3, 4, 5]
y_data = [20, 50, 30, 40, 10]
plt.scatter(x_data, y_data)
plt.show()