简体   繁体   中英

Residual plot axis not lining up with graph axes

I am trying to plot a residual plot beneath my graph but seem to be unable to get the same scaling on my axes to line up the points correctly. Here is my code:

# Plot with residuals


fig1 = plt.figure(figsize =(10,8))


ax = fig1.add_axes((0.2,0.4,.75,.6))

ax.plot(JD_inc, mag_inc, 'x', new_x_inc, new_y_inc)
ax.plot(JD_dec, mag_dec, 'x', new_x_dec, new_y_dec)

ax.errorbar(our_jul_day, our_mag, yerr = our_err, fmt = "x", color = "black", zorder = 10)

ax.plot(x_line,y_line, linestyle = "--", color = "black", zorder = 0)

ax.plot(JD_start, mag_start, 'x', zorder = 1, color = 'darkorchid')

ax.invert_yaxis()



positions = (2458725, 2458775, 2458825,2458875, 2458925)
labels = (2458725, 2458775, 2458825,2458875, 2458925)
plt.xticks(positions, labels)


ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')

# Axis labels
plt.xlabel('Julian Date', fontsize = 12)
plt.ylabel('Magnitude', fontsize = 12)



ax2 = fig1.add_axes((0.2,0.2,.75,0.2)) 
plt.xlabel("Julian Date", fontsize = 12)
plt.ylabel("Magnitude", fontsize = 12)    #\n is used to start a new line


ax2.plot(JD_inc,res_inc,"x")
ax2.plot(JD_dec,res_dec,"x", color = 'forestgreen')
ax2.plot(JD_start,res_start,'x', color = 'darkorchid')
ax2.plot(our_jul_day, res_our_data, 'x', color = 'black')

positions = (2458725, 2458775, 2458825,2458875, 2458925)
labels = (2458725, 2458775, 2458825,2458875, 2458925)
plt.xticks(positions, labels)




ax2.spines['right'].set_visible(False)
ax2.yaxis.set_ticks_position('left')
ax2.xaxis.set_ticks_position('bottom')

ax2.invert_yaxis()

plt.axhline(0, linewidth=1, linestyle="--", color="black")

I believe the problem comes from me not understanding what the arguments of fig.add_axes are.

Here is what my graph currently looks like:

I seemed to have fixed the problem by setting limits to the x-axes for both graphs ie:

ax.set_xlim([2458725, 2458940])
ax2.set_xlim([2458725, 2458940])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM