import numpy as np import matplotlib.pyplot as plt x = np.arange(-5, 5, 0.1) y1 = np.sin(x) y2 = np.cos(x) plt.title("graph") plt.xlabel("x") plt.ylabel("y") plt.plot(x, y1, label="sin x") # labelに凡例に表示する文字を指定 plt.plot(x, y2, label="cos x") plt.legend() # 凡例を表示 plt.xlim(-np.pi, np.pi) plt.ylim(-1.2, 1.2) plt.show()