如何使用Matplotlib强制呈现误差条?
要使用matplotlib强制呈现误差条,我们可以执行以下步骤-
- 设置图形大小并调整子图之间以及周围的填充。
- 使用 figure() 方法创建新图或激活现有图。
- 使用 gca() 方法获取当前轴。
- 绘制线列表。
- 使用附加误差条绘制 y 相对于 x 的线和/或标记。
- 要显示图形,请使用 show() 方法。
示例
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = plt.gca()
[ax.plot(np.random.rand(10)) for j in range(10)]
ax.errorbar(range(10), np.random.rand(10), yerr=.3 * np.random.rand(10))
plt.show()