0

I have following piece of code

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()

This creates the following diagram:

Screenshot 1

I want to add vertical lines to the axes so that the diagram looks like this:

Screenshot 2

Is it possible to do it? If yes, how?

  • 1
    Try `plt.gca().yaxis.grid(True)` – BenT Jun 21 '19 at 21:12
  • Thanks, but it did not work. –  Jun 21 '19 at 21:15
  • 1
    Seems like a duplicate of this: https://stackoverflow.com/questions/16074392/getting-vertical-gridlines-to-appear-in-line-plot-in-matplotlib, but it appears you want to draw the vertical lines at arbitrary positions? – rcriii Jun 21 '19 at 21:26
  • @rcriii Thanks for your comment. No, they are not an arbitrary positions. On the x axis you have ticks for each value (*Step 0* is one tick, *Step 1* another etc.) I want these ticks to be higher so that I can see where one step ends and another begins. –  Jun 22 '19 at 10:23
  • 1
    Please read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Sheldore Jun 22 '19 at 11:33

1 Answers1

0

View matplotlib documentation on ax.axvline This should give you the ability to draw vertical lines at specified x position and with specified start and end point.

sphexoo
  • 73
  • 2
  • 7