Is there a way to stretch the png image to fit the scatter plot?

I need to understand a way to make the map fit the scatter plot points

I've looked for solutions and have found matplotlib and apect ratio of geographical-data plots to be somewhat helpful, but I still do not understand longitude and latitude and how to work with them in matplotlib. I've tried changing the aspect to 'equal' and it only makes a small difference in the points. My theory at the moment is I need to figure out how to find the correct aspect ratio by doing some math to make the image fit the points, but I'm not sure what to calculate.

enter image description here

is what it currently looks like, and you can see the general shape of the US from the eastern points. How would I go about this problem? Any references or sources where I can learn more about this would be awesome.

coordinatelist = [list of longitude and latitude coordinates] #order of coordinates => [longitude min, longitude max, latitude min, latitude max] coords = [-160.2, -65.5, 14.5, 65.7] img= plt.imread(path) width = 636 #width of image in pixels height = 485 #height of image in pixels fig, axes = plt.subplots(figsize = (10,9)) axes.scatter(coordinatelist.longitude, coordinatelist.latitude, zorder=1, alpha= 0.4, c='r', s=8) axes.set_xlim(coords[0],coords[1]) axes.set_ylim(coords[2],coords[3]) axes.imshow(img, zorder=0, extent = coords, aspect = 'auto') plt.show() 

I would like the points to match the background image, and if possible an explanation of how to reproduce the results so I can gain a deeper understanding. Thank you!

5

1 Answer

Solved:

Manually changing the extent of the map was an unnecessary and inconsistent solution. Openstreemap was exporting the incorrect dimensions which I was not aware of at the time. I found that simply creating your coordinate box on OSM did not actually export what was specified unless you also set custom dimensions.

Upon paying attention to the details closer, the correct size map was exported and the map fit the scatter plots.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like