【发布时间】:2019-11-28 11:03:27
【问题描述】:
我想要只有沿 x 轴的刻度和标签的箱线图(水平)。但是,当循环到达轴 = 12 时,它会将刻度和标签添加到 y 轴,即使它已从轴 = 1 删除到轴 = 11。
代码:
import matplotlib.pyplot as plt
import seaborn as sns
fig,axs = plt.subplots(12,3,figsize=(15,50),dpi=200)
fig.suptitle("Box plot for all 34 features",fontsize=16)
fig.tight_layout()
plt.subplots_adjust(top=0.96)
i=1
for column in undersampled_data:
if (column == 'TimeStamp' or column == 'Status'):
continue
ax = fig.add_subplot(12,3,i)
ax.set_title(column)
sns.boxplot(undersampled_data[column],palette="Set2")
ax.set_xlabel('')
# Removing y ticks and y labels
frame1 = plt.gca()
frame1.axes.yaxis.set_ticklabels([])
frame1.axes.get_yaxis().set_ticks([])
print(i ," ",column)
i+=1
for j in range(0,(len(axs)-1)):
fig.delaxes(axs.flatten()[j])
fig.subplots_adjust(hspace=0.4)
【问题讨论】:
-
考虑到您已经在命令 fig,axs = ... 中定义了图。我不确定您为什么要在循环中再次添加它们。另外你已经有了元素 ax,所以我认为没有必要再次使用 plt.gca 来获取它们
标签: python matplotlib boxplot subplot