Các bước
- Thiết lập kích thước hình và padding.
- Áp dụng style
fivethirtyeight bằng plt.style.use().
- Tạo dữ liệu
x bằng numpy.
- Tạo figure và subplots.
- Vẽ ba đường cong bằng
plot().
- Đặt tiêu đề.
- Gọi
show().
Ví dụ
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.style.use('fivethirtyeight')
x = np.linspace(0, 10)
fig, ax = plt.subplots()
ax.plot(x, np.sin(x) + x + np.random.randn(50))
ax.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
ax.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
ax.set_title("'fivethirtyeight' style sheet")
plt.show()
Kết quả
