Search code examples
pythonmatplotlibx-axis

How to change the limits of axes


I have plot where the x-axis starts from 0-100. I want to change it to 10-100. I would be grateful if someone could give any suggestion.


Solution

  • If you just use pyplot for a simple plot, you can try this function:

    import matplotlib.pyplot as plt
    ...
    plt.xlim(10, 100)
    

    If you want to set specific axes, you can try this method:

    import matplotlib.pyplot as plt
    ...
    ax = plt.gca()
    ax.set_xlim(10, 100)