0

I would like to plot some coordinates on top of an image. I want to invert the axis for the said coordinates but not for the image. But with my code, the axis gets inverted for both the image and the coordinates.

This is my code:

    import numpy as np
    from matplotlib import pyplot as plt
    plt.rcParams["figure.figsize"] = [10, 10]
    plt.rcParams["figure.autolayout"] = True
    im = plt.imread("bird.png")
    fig, ax = plt.subplots()
    im = ax.imshow(im, extent=[0, 720, 0, 576])
    x = np.array(range(300))
    fig.gca().invert_xaxis()
    fig.gca().invert_yaxis()
    ax.scatter(x_coords_true, y_coords_true, color='red')
    ax.scatter(x_coords_pred, y_coords_pred, color='yellow')
    plt.show()

Can you help me modify the code to get the result I am expecting, please?

S.San
  • 17
  • 3
  • 1
    [Flip your image while importing](https://stackoverflow.com/a/14590351/8881141)? – Mr. T Jan 17 '22 at 10:14
  • 1
    You can monkey around with `imshow` and extent, and flipping the data or the extent. https://matplotlib.org/stable/tutorials/intermediate/imshow_extent.html However, often it is easier to generate an x and y and use pcolormesh. – Jody Klymak Jan 17 '22 at 10:20
  • `imshow(...., origin='lower')` – JohanC Jan 17 '22 at 12:50

0 Answers0