1. 선 그래프
import matplotlib.pyplot as plt
x = range(1, 6)
y1 = [0.01, 0.019, 0.042, 0.038, 0.062] # 함수로 해도 됨
y2 = [0.02, 0.021, 0.03, 0.036, 0.044]
plt.plot(x, y1, label="Label 1") # y1 데이터 라벨
plt.plot(x, y2, label="Label 2") # y2 데이터 라벨
plt.xlabel("X Label") # X 축 라벨
plt.ylabel("Y Label") # Y 축 라벨
plt.title('Title')
plt.legend() # Places a legend(범례) on the axes.
plt.show()
2. 막대 그래프
import matplotlib.pyplot as plt
times = [0.0073, 0.2327, 0.5721, 1.6407, 1.8450, 3.5439]
ax = plt.subplot()
ax.set_xticks([0, 1, 2, 3, 4, 5])
ax.set_xticklabels(['sorted()', 'countSort()', 'introSort()',
'timSort()', 'quickSort()', 'smoothSort()'], rotation=10)
plt.bar(range(len(times)), times)
plt.title('Sorting Algorithms')
plt.ylabel('Times (sec)')
plt.show()