[英]How can I draw the right and top axis and remove the left and bottom axis in a Pairplot of Seaborn?
这实际上不是一件容易的事,因为您需要处理许多由 seaborn 硬编码的东西(刺、刻度、标签)。
sns.set_style('ticks')
penguins = sns.load_dataset("penguins")
g=sns.pairplot(penguins)
for ax in g.axes.flat:
sns.despine(left=True, right=False, bottom=True, top=False, ax=ax)
ax.xaxis.set_ticks_position('top')
ax.yaxis.set_ticks_position('right')
plt.setp(ax.yaxis.get_ticklabels(), visible=ax.is_last_col())
plt.setp(ax.xaxis.get_ticklabels(), visible=ax.is_first_row())
for ax1,ax2 in g.axes[:,[0,-1]]:
ax2.yaxis.set_label_position('right')
ax2.set_ylabel(ax1.get_ylabel(), visible=True)
ax1.set_ylabel('')
for ax1,ax2 in g.axes[[0,-1],:].T:
ax1.xaxis.set_label_position('top')
ax1.set_xlabel(ax2.get_xlabel(), visible=True)
ax2.set_xlabel('')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.