![](/img/trans.png)
[英]How to add vertical tick marks to all horizontal grid lines in matplotlib?
[英]How to add vertical grid lines to a matplotlib chart?
我有以下代碼
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()
這將創建以下圖:
我想在軸上添加垂直線,以便該圖如下所示:
有可能做到嗎? 如果是,怎么辦?
在ax.axvline上查看matplotlib文檔。這應該使您能夠在指定的x位置以及指定的起點和終點繪制垂直線。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.