1

I'm trying to, for simplicity's sake, plot a line over a 2D histogram, with both the line and the histogram points referring to latitude/longitude coordinates.

Here's an example of the sort of thing I'm trying to do:

import numpy as np
import matplotlib.pyplot as plt
img = np.random.rand(10,10)
longs = [100,101]
lats = [45,46]
x = np.linspace(100,100)
y = np.linspace(45,46)

plt.figure()
plt.imshow(img,extent=[longs[0],longs[1],lats[0],lats[1]])
plt.plot(x,y)
plt.show()

1 Answer 1

1

Your approach is correct, however you cannot see the line for 2 reasons.

1) Your x axis limits are 100 and 101, and you are trying to plot the vertical line at x=100.

2) The default color of the line might make it hard to see

By changing x to 100.5 using

x = np.linspace(100.5,100.5)

and changing the color of the line to black

plt.plot(x, y, color="k")

The plot becomes

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks! I was trying to plot a diagonal line which goes from bottom right to top left, but I've changed the colour of the line and it now appears to work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.