简体   繁体   中英

Matplotlib multiple graphs, extra space underneath x-axis

Trying mathplotlib for the first time. I want to create two separate graphs. I'm able to get both graphs to show, however, the second graph has extra space underneath the x-axis and makes the x-axis scale labels/axis label show way below. If I comment out the first graph, the extra space disappears.

I've attempted using plt.tight_layout() and that made the rest of the graph tight (labels were laying over-each other), but did not help w/ my extra space at the bottom. see the right graph with the red marking

Note: I changed the configuration on the right graph to show the extra space, so that's why it'll look different than the ranges I included in the code.

#left graph
fig_Sub = plt.figure(1)
fig_Sub.suptitle('Subreddits', fontsize=14, fontweight='bold')
ax1 = fig_Sub.add_subplot(111)
fig_Sub.subplots_adjust(top=0.85)
ax1.set_title('axes title')
ax1.set_xlabel('Word')
y_rotate=ax1.set_ylabel('Instances')
y_rotate.set_rotation(0)
ax1.axis([0, 1000, 0, 1000])
plt.rc('xtick', color='k', labelsize='medium', direction='out')
plt.rc('xtick.major', size=10, pad=100) #size of tick, interval
plt.rc('xtick.minor', size=10, pad=100)

#right graph
fig_user = plt.figure(2)
fig_user.suptitle('Users', fontsize=14, fontweight='bold')
ax2 = fig_user.add_subplot(111)
fig_user.subplots_adjust(top=0.85)
ax2.set_title('axes title')
ax2.set_xlabel('Word')
y2_rotate=ax2.set_ylabel('Instances')
y2_rotate.set_rotation(0)
ax2.axis([0, 1000, 0, 1000])
plt.rc('xtick', color='k', labelsize='medium', direction='out')
plt.rc('xtick.major', size=0, pad=0)
plt.rc('xtick.minor', size=0, pad=0)
plt.show()

根据@ImportanceOfBeingErnest,删除plt.rc()中的pad。

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