matplotlib中的R型数据轴缓冲区 [英] R style data-axis buffer in matplotlib

查看:45
本文介绍了matplotlib中的R型数据轴缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R图会自动设置x和y极限,以在数据和轴之间放置一些空间.我想知道 matplotlib 是否有办法自动执行相同的操作.如果没有,是否有关于 R 如何设置其轴限制的好的公式或经验法则"?

R plots automatically set the x and y limits to put some space between the data and the axes. I was wondering if there is a way for matplotlib to do the same automatically. If not, is there a good formula or 'rule of thumb' for how R sets its axis limits?

推荐答案

查看参数 xaxs ?par :

用于x轴的轴间隔计算方式.可能的值为"r","i","e","s","d".如果给定,样式通常由数据范围或 xlim 控制.
样式r"(常规)首先在每一端将数据范围扩展 4%,然后找到一个带有适合扩展范围的漂亮标签的轴.

The style of axis interval calculation to be used for the x-axis. Possible values are "r", "i", "e", "s", "d". The styles are generally controlled by the range of data or xlim, if given.
Style "r" (regular) first extends the data range by 4 percent at each end and then finds an axis with pretty labels that fits within the extended range.

所以,如果我们尝试一下:

So if we try this out:

par(xaxs="r")       #The default  
plot(1:10, 1:10)

我们实际上可以证明它是每侧范围的+/- 4%:

We can actually demonstrate that it's +/- 4% of the range on each side:

abline(v=1-(diff(range(1:10)))*0.04, col="red")
abline(v=10+(diff(range(1:10)))*0.04, col="red")

这篇关于matplotlib中的R型数据轴缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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