如何使用 matplotlib 和 seaborn 轴 [英] How to despine a matplotlib and seaborn axes

查看:61
本文介绍了如何使用 matplotlib 和 seaborn 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在图中打开和关闭坐标轴,也很难适当调整坐标轴的大小.我遵循了几个线程,我的方法是:

I'm having difficulty turning the axes on and off in plots, and sizing my axes appropriately. I've followed several threads and my method is:

f1=plt.figure(1,(3,3))
ax=Subplot(f1,111)
f1.add_subplot(ax)
ax.scatter(current,backg,label='Background Height')
ax.plot(current,backg)
ax.scatter(current,peak,color = 'red',label='Peak Spot Height')
ax.plot(current,peak,color='red')
ax.plot(current,meanspot,color='green')
ax.scatter(current,meanspot,color = 'green',label='Mean Spot Height')

ax.spines['left'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

但是我的图形仍然在顶部和右侧带有轴,并且由于轴的大小而出现奇怪的间隙.

But my figures still end up with axes on the top and right, and a strange gap due to the sizing of the axes.

推荐答案

你能具体点需要什么吗?

Can you be more specific what's needed?

您可以通过以下方式移除脊椎:

You can remove the spine with:

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

但听起来您可能指的是脊椎上的蜱虫...

But it sounds like you might be referring to ticks on the spine...

这篇关于如何使用 matplotlib 和 seaborn 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆