How to zoomed a portion of image and insert in the same plot in matplotlib

前端 未结 4 456
太阳男子
太阳男子 2020-12-02 05:19

I would like to zoom a portion of data/image and plot it inside the same figure. It looks something like this figure.

4条回答
  •  执念已碎
    2020-12-02 06:01

    The basic steps to zoom up a portion of a figure with matplotlib

    import numpy as np
    from matplotlib import pyplot as plt
    
    # Generate the main data
    X = np.linspace(-6, 6, 1024)
    Y = np.sinc(X)
    
    # Generate data for the zoomed portion
    X_detail = np.linspace(-3, 3, 1024)
    Y_detail = np.sinc(X_detail)
    
    # plot the main figure
    plt.plot(X, Y, c = 'k')  
    
     # location for the zoomed portion 
    sub_axes = plt.axes([.6, .6, .25, .25]) 
    
    # plot the zoomed portion
    sub_axes.plot(X_detail, Y_detail, c = 'k') 
    
    # insert the zoomed figure
    # plt.setp(sub_axes)
    
    plt.show()
    

提交回复
热议问题