如何为上限设置“自动",但通过matplotlib.pyplot保持固定的下限 [英] How to set 'auto' for upper limit, but keep a fixed lower limit with matplotlib.pyplot

查看:130
本文介绍了如何为上限设置“自动",但通过matplotlib.pyplot保持固定的下限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 y 轴的上限设置为自动",但我想保持 y 轴的下限始终为零.我尝试了自动"和自动调整范围",但那些似乎不起作用.预先谢谢你.

I want to set the upper limit of the y-axis to 'auto', but I want to keep the lower limit of the y-axis to always be zero. I tried 'auto' and 'autorange', but those don't seem to work. Thank you in advance.

这是我的代码:

import matplotlib.pyplot as plt

def plot(results_plt,title,filename):

    ############################
    # Plot results

    # mirror result table such that each parameter forms an own data array
    plt.cla()
    #print results_plt
    XY_results = []

    XY_results = zip( *results_plt)

    plt.plot(XY_results[0], XY_results[2], marker = ".")

    plt.title('%s' % (title) )
    plt.xlabel('Input Voltage [V]')
    plt.ylabel('Input Current [mA]')

    plt.grid(True)
    plt.xlim(3.0, 4.2)  #***I want to keep these values fixed"
    plt.ylim([0, 80]) #****CHANGE**** I want to change '80' to auto, but still keep 0 as the lower limit 
    plt.savefig(path+filename+'.png')

推荐答案

您可以将 leftright 传递给 set_xlim:

You can pass just left or right to set_xlim:

plt.gca().set_xlim(left=0)

对于 y 轴,使用 bottomtop:

For the y axis, use bottom or top:

plt.gca().set_ylim(bottom=0)

这篇关于如何为上限设置“自动",但通过matplotlib.pyplot保持固定的下限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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