setting y-axis limit in matplotlib

后端 未结 9 1823
自闭症患者
自闭症患者 2020-11-22 15:42

I need help with setting the limits of y-axis on matplotlib. Here is the code that I tried, unsuccessfully.

import matplotlib.pyplot as plt

plt.figure(1, fi         


        
9条回答
  •  礼貌的吻别
    2020-11-22 16:42

    To add to @Hima's answer, if you want to modify a current x or y limit you could use the following.

    import numpy as np # you probably alredy do this so no extra overhead
    fig, axes = plt.subplot()
    axes.plot(data[:,0], data[:,1])
    xlim = axes.get_xlim()
    # example of how to zoomout by a factor of 0.1
    factor = 0.1 
    new_xlim = (xlim[0] + xlim[1])/2 + np.array((-0.5, 0.5)) * (xlim[1] - xlim[0]) * (1 + factor) 
    axes.set_xlim(new_xlim)
    

    I find this particularly useful when I want to zoom out or zoom in just a little from the default plot settings.

提交回复
热议问题