简体   繁体   English

Matplotlib多个图,x轴下方有额外空间

[英]Matplotlib multiple graphs, extra space underneath x-axis

Trying mathplotlib for the first time. 第一次尝试mathplotlib。 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. 我能够同时显示两个图形,但是第二个图形在x轴下方有额外的空间,并使x轴比例标签/轴标签显示如下。 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. 我曾尝试使用plt.tight_layout(),这使其余图变紧(标签彼此叠放),但并没有帮助我在底部增加额外的空间。 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。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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