在 Matplotlib 中的 fivethirtyeight 样式表中绘制曲线
matplotlibpythondata visualization更新于 2025/6/23 14:36:17
要使用 fivethirtyeight 样式表,我们可以采取以下步骤 −
- 设置图形大小并调整子图之间和周围的填充。
- 要使用 fivethirtyeight,我们可以使用 plt.style.use() 方法。
- 使用 numpy 创建 x 个数据点。
- 使用 subplots() 方法创建一个图形和一组子图。
- 使用 plot() 方法绘制三条曲线。
- 设置绘图的标题。
- 要显示图形,请使用 show() 方法。
示例
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()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

