Matplotlib imshow offset to match axis?

前端 未结 1 439
有刺的猬
有刺的猬 2020-12-10 12:16

I\'m plotting a bunch of UTM coordinates using a matplotlib.pyplot.scatter. I also have a background air photo that I know matches the extent of the figure exactly. When I p

相关标签:
1条回答
  • 2020-12-10 13:02

    You need to use the extent keyword argument to imshow.

    As a quick example:

    import numpy as np
    import matplotlib.pyplot as plt
    
    # Random points between 50000 and 51000
    x, y = 1000 * np.random.random((2, 10)) + 50000
    
    # A 10x10 "image"...
    image = np.arange(100).reshape((10,10))
    
    # In a lot of cases, image data will be "flipped" vertically, so you may need 
    # use the `origin` kwarg, as well (or just swap the ymin and ymax ordering).
    plt.imshow(image, extent=[x.min(), x.max(), y.min(), y.max()])
    plt.plot(x, y, 'ro')
    
    plt.show()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题