【发布时间】:2019-11-04 17:19:23
【问题描述】:
我有以下代码
import matplotlib.pyplot as plt
import numpy as np
[...]
def display(self):
t = self.stateLabels
fig, axs = plt.subplots(4, 1, sharex=True)
fig.subplots_adjust(hspace=0)
axs[0].plot(t, self.production)
axs[0].title.set_text('Production')
axs[0].frameon = True
axs[1].plot(t, self.consumption)
axs[1].title.set_text('Consumption')
axs[2].plot(t, self.investment)
axs[2].title.set_text('Investment')
axs[3].plot(t, self.gdp)
axs[3].title.set_text('GDP')
plt.show()
这将创建以下图表:
我想在轴上添加垂直线,使图表看起来像这样:
有可能吗?如果是,怎么做?
【问题讨论】:
-
试试
plt.gca().yaxis.grid(True) -
谢谢,但没用。
-
好像是这个的副本:stackoverflow.com/questions/16074392/…,但您似乎想在任意位置绘制垂直线?
-
@rcriii 感谢您的评论。不,它们不是任意位置。在 x 轴上,每个值都有刻度(Step 0 是一个刻度,Step 1 是另一个刻度,等等。)我希望这些刻度更高,以便我可以看到在哪里一步结束,另一步开始。
标签: python python-3.x matplotlib