pandas - Python: "Squeeze" a particular plot in subplot -



pandas - Python: "Squeeze" a particular plot in subplot -

below, plot next figure in python:

as can see plot on right much more "smooth" 1 on left. that's because scaling of x-axis on both plot different. more observations on left on right (about 3 times more). hence how can "squeeze" horizontally right plot such approximative 1 of left? below code (i utilize pandas):

fig, axes = plt.subplots(1, 2, sharey=true, figsize=(30, 15)) # plot same info on both axes #gs = gridspec.gridspec(1, 2, width_ratios=[3, 1]) ax1 = df1.plot(ax=axes[0], grid='off', legend=false, xticks=[-250, -200, -150, -100, -50, 0, 25], lw=2, colormap='jet', fontsize=20) ax2 = df2.plot(ax=axes[1], grid='off', legend=false, xticks=[-5, 0, 20, 40, 60, 80], lw=2, colormap='jet', fontsize=20) # zoom-in / limit view different portions of info # hide spines between ax , ax2 ax1.set_ylabel('treatment-control ratio', fontsize=20) ax1.axhline(y=1, color='r', linewidth=1.5) ax2.axhline(y=1, color='r', linewidth=1.5) ax1.axvline(x=0, color='r', linewidth=1.5, linestyle='--') ax2.axvline(x=0, color='r', linewidth=1.5, linestyle='--') ax1.set_xlabel('event time - 1 minute', fontsize=20) ax2.set_xlabel('event time - 1 minute', fontsize=20) ax1.spines['right'].set_visible(false) ax2.spines['left'].set_visible(false) ax1.yaxis.tick_left() ax2.yaxis.set_major_locator(plt.nulllocator()) ax1.tick_params(labeltop='off') # don't set tick labels @ top plt.subplots_adjust(wspace=0.11) plt.tight_layout()

with help of @cphlewis , @gboffi fixed issue code below:

fig, axes = plt.subplots(figsize=(30, 15)) # plot same info on both axes gs = gridspec.gridspec(1, 2, width_ratios=[3, 1.2]) ax1 = plt.subplot(gs[0]) ax2 = plt.subplot(gs[1], sharey=ax1) df_wpc.loc[-260:25].plot(ax=ax1, grid='off', legend=false, xticks=[-250, -200, -150, -100, -50, 0, 25], lw=2, colormap='jet', fontsize=20) df_pc_et.loc[-5:91].plot(ax=ax2, grid='off', legend=false, xticks=[-5, 0, 20, 40, 60, 80], lw=2, colormap='jet', fontsize=20) ax1.set_ylabel('treatment-control ratio', fontsize=20) ax1.axhline(y=1, color='r', linewidth=1.8) ax2.axhline(y=1, color='r', linewidth=1.8) ax1.axvline(x=0, color='r', linewidth=1.8, linestyle='--') ax2.axvline(x=0, color='r', linewidth=1.8, linestyle='--') ax1.set_xlabel('event time - 1 minute', fontsize=20) ax2.set_xlabel('event time - 1 minute', fontsize=20) ax1.spines['right'].set_visible(false) ax2.spines['left'].set_visible(false) ax1.yaxis.tick_left() ax2.yaxis.set_major_locator(plt.nulllocator()) ax1.tick_params(labeltop='off') # don't set tick labels @ top plt.subplots_adjust(wspace=0.7) plt.tight_layout()

python pandas matplotlib plot

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -