簡體   English   中英

如何在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()

這將創建以下圖:

屏幕截圖1

我想在軸上添加垂直線,以便該圖如下所示:

屏幕截圖2

有可能做到嗎? 如果是,怎么辦?

ax.axvline上查看matplotlib文檔。這應該使您能夠在指定的x位置以及指定的起點和終點繪制垂直線。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM