twinx and grid

The script below labels both the left and right x-axes and shows a grid. Is
there a way to force the horizontal grid lines to line up with the tic marks on
the left axis (ax1)?

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r')
plt.grid()
plt.show()

2014-02-09 2:29 GMT+01:00 garyr <garyr@...4486...>:

The script below labels both the left and right x-axes and shows a grid. Is
there a way to force the horizontal grid lines to line up with the tic marks on
the left axis (ax1)?

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r')
plt.grid()
plt.show()

plt.grid() affects the current axes so calling it before creating the
second one should do. I think it would be more consistent if you used
the method ax1.grid() though.

Goyo