'Plotting coordinate data on top of a map in Python matplotlib

So, what I am having trouble with is how I am supposed to plot the data I have on top of a global map. I have an array of data, and two arrays of coordinates in latitude and longitude, where each datapoint was taken, but I am not sure of how to plot it on top of a global map. Creating the map itself is not too difficult, I just use:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

fig = plt.figure(figsize=(10, 8))
m = Basemap(projection='cyl', resolution='c',
            llcrnrlat=-90, urcrnrlat=90,
            llcrnrlon=-180, urcrnrlon=180, )
m.shadedrelief(scale=0.5)
m.drawcoastlines(color='black')

But the next step is where I am having problems. I have tried doing both a colormesh plot and scatter plot, but they haven't worked so far. How should I go about it so that the data is plotted in the correct coordinate locations for the global map?

Thanks a lot for any help!



Solution 1:[1]

Maybe a bit late, but I have this piece of code I used to plot multiple linear plot over a map in Basemap that worked for me.

map = Basemap(projection='cyl', resolution='c',
            llcrnrlat=mins[1], urcrnrlat=maxs[1],
            llcrnrlon=mins[0], urcrnrlon=50, )
plt.figure(figsize=(15, 15))
for i in range(1259): 
    filepath = filename[i]
    data = pd.read_csv(filepath, index_col=0)
    map.plot(data.x,data.y,'k-', alpha=0.1) ### Calling the plot in a loop!!
map.drawcoastlines(linewidth=1)
map.drawcountries(linewidth=0.5, linestyle='solid', color='k' ) 
plt.show()

The loop calls data from different folders, and I just use the map.plot command to plot. By doing it like that, you can plot all data in the same map.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak