Matplotlib - fixing x axis scale and autoscale y axis

前端 未结 3 1776
时光说笑
时光说笑 2020-12-01 13:59

I would like to plot only part of the array, fixing x part, but letting y part autoscale. I tried as shown below, but it does not work.

Any suggestions?

<         


        
3条回答
  •  执念已碎
    2020-12-01 14:43

    Autoscaling always uses the full range of the data, so the y-axis is scaled by full extent of the y-data, not just what's within the x-limits.

    If you'd like to display a subset of the data, then it's probably easiest to plot only that subset:

    import numpy as np
    import matplotlib.pyplot as plt
    
    x, y = np.arange(0,101,1) ,300 - 0.1*np.arange(0,101,1)
    mask = (x >= 50) & (x <= 100)
    
    fig, ax = plt.subplots()
    ax.scatter(x[mask], y[mask])
    
    plt.show()
    

提交回复
热议问题