有没有办法告诉matplotlib放宽对绘制数据的缩放? [英] Is there a way to tell matplotlib to loosen the zoom on the plotted data?

查看:75
本文介绍了有没有办法告诉matplotlib放宽对绘制数据的缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绘制了一些数据,其中包括每个子图上的一些限制:两个轴都具有限制,但由于数据非常适合第二个图的限制,因此限制本身设置了y轴的边界,使它们不可见.

I have some data plotted which includes some limits on each subplot: Both axes have the limits, but since the data fits so nicely within the limits on the second plot, the limits themselves set the boudaries for the y-axis, making them invisible.

要使它们可见,我可以做这样的事情:

To make them visible, I could do something like this:

axes.set_ylim(1.1*lowerLimit,1.1*upperLimit)

其中lowerLimitupperLimit首先是用于生成限制的数据,但是我想知道matplotlib是否具有一种机制来告知它不要自动设置限制.我现在拥有的解决方案还有一个局限性,即如果数据偏离边界,则有可能超出界限,因此我搜索了set_ylim()的补码,它将告诉我限制是什么,就像get_ylim()一样,但是文档中似乎不存在.

where lowerLimit and upperLimit are the data used to generate the limits in the first place, but I am wondering if matplotlib has a mechanism to tell it to not be so zealous in it's automatic setting of the limits. The solution I have now also has the limitation that if the data deviates from the boundaries, it risks going outside the lines, so I searched for a complement to set_ylim() which would tell me what the limits are, somehting like get_ylim() but it does not seem to exist in the documentation.

感谢您的帮助.

推荐答案

关于您要求更改y轴限制的功能,这是否适合您的目的?

In regards to your request for a function to change the y-axis limits, would this suit your purposes?:

def larger_axlim( axlim ):
    """ argument axlim expects 2-tuple 
        returns slightly larger 2-tuple """
    axmin,axmax = axlim
    axrng = axmax - axmin
    new_min = axmin - 0.1 * axrng
    new_max = axmax + 0.1 * axrng
    return new_min,new_max
...
ax.set_ylim( larger_axlim( ax.get_ylim() ) )
...

文档: get_ylim()

这篇关于有没有办法告诉matplotlib放宽对绘制数据的缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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