How to sharex and sharey axis in for loop
<p>I'm trying to share the x-axis and y-axis of my sumplots, I've tried using the sharey and sharex several different ways but haven't gotten the correct result.</p>

<pre><code>ax0 = plt.subplot(4,1,1)
for i in range(4):
    plt.subplot(4,1,i+1,sharex = ax0)
    plt.plot(wavelength[i],flux)
    plt.xlim([-1000,1000])
    plt.ylim([0,1.5])
    plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
</code></pre>

<p>If I understood you correctly, want to have four stacked plots, sharing the x-axis and the y-axis.  This you can do with <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplots" rel="nofollow">plt.subplots</a> and the keywords <code>sharex=True</code> and <code>sharey=True</code>.  See example below:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt

fig, axlist = plt.subplots(4, 1, sharex=True, sharey=True)
for ax in axlist:
    ax.plot(np.random.random(100))

plt.show()
</code></pre>

python matplotlib