I\'m using this line of code to create a vertical span across a graph using matplotlib.
matplotlib.pyplot.axvspan(datetime.datetime.strptime(\"09-10-2015\",
It's not about transparency (which you can change with the alpha
parameter). It's about zorder
(a kind of distance to the user, lower zorder will be farther). You need to put the zorder of the grid
below the zorder of the axvspan
(which in turn should be below, I think, of the plot
). Check the following example:
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(-1, 2, .01)
s = np.sin(2*np.pi*t)
plt.plot(t, s,zorder=4)
p = plt.axvspan(1.25, 1.55, facecolor='g', alpha=1,zorder=3)
plt.axis([-1, 2, -1, 2])
plt.grid(zorder=2)
plt.show()
, which results in: