虽然我可以将代码拼凑在一起绘制XY图,但我想要一些额外的东西:

如何在mathplotlib中创建这样的图形?
你可以这样做:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
data = (0, 2, 3, 5, 5, 5, 9, 7, 8, 6, 6)
ax.plot(data, 'r-', linewidth=4)
plt.axvline(x=5, ymin=0, ymax=4.0 / max(data), linewidth=4)
plt.text(5, 4, 'your text here')
plt.show()
Run Code Online (Sandbox Code Playgroud)
注意,有些奇怪的是ymin和ymax值的运行0 to 1,因此需要对轴进行标准化

编辑: OP修改了代码使其更加OO:
fig = plt.figure()
data = (0, 2, 3, 5, 5, 5, 9, 7, 8, 6, 6)
ax = fig.add_subplot(1, 1, 1)
ax.plot(data, 'r-', linewidth=4)
ax.axvline(x=5, ymin=0, ymax=4.0 / max(data), linewidth=4)
ax.text(5, 4, 'your text here')
fig.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6691 次 |
| 最近记录: |