def align_subplots(N,M,xlim=None, ylim=None):
<EOL>if xlim is None:<EOL><INDENT>xlim = [np.inf,-np.inf]<EOL>for i in range(N*M):<EOL><INDENT>plt.subplot(N,M,i+<NUM_LIT:1>)<EOL>xlim[<NUM_LIT:0>] = min(xlim[<NUM_LIT:0>],plt.xlim()[<NUM_LIT:0>])<EOL>xlim[<NUM_LIT:1>] = max(xlim[<NUM_LIT:1>],plt.xlim()[<NUM_LIT:1>])<EOL><DEDENT><DEDENT>if ylim is None:<EOL><INDENT>ylim = [np.inf,-np.inf]<EOL>for i in range(N*M):<EOL><INDENT>plt.subplot(N,M,i+<NUM_LIT:1>)<EOL>ylim[<NUM_LIT:0>] = min(ylim[<NUM_LIT:0>],plt.ylim()[<NUM_LIT:0>])<EOL>ylim[<NUM_LIT:1>] = max(ylim[<NUM_LIT:1>],plt.ylim()[<NUM_LIT:1>])<EOL><DEDENT><DEDENT>for i in range(N*M):<EOL><INDENT>plt.subplot(N,M,i+<NUM_LIT:1>)<EOL>plt.xlim(xlim)<EOL>plt.ylim(ylim)<EOL>if (i)%M:<EOL><INDENT>plt.yticks([])<EOL><DEDENT>else:<EOL><INDENT>removeRightTicks()<EOL><DEDENT>if i<(M*(N-<NUM_LIT:1>)):<EOL><INDENT>plt.xticks([])<EOL><DEDENT>else:<EOL><INDENT>removeUpperTicks()<EOL><DEDENT><DEDENT>
make all of the subplots have the same limits, turn off unnecessary ticks