Trying to plot DATA POINTS on BASEMAP (Python)

Viewed 1314

I have some meteorological data about some stations in Tenerife Island (this Dataframe has lat,lon and temperature in certain points of the island) (The source of the data is AEMET opendata, so they are supposed to be trustworthy)

I have plotted the Basemap successfully, but when I wanted to plot the points in my Dataframe over the Basemap, the come really weird.
Here the data I have:

enter image description here

I changed the order so, when I use imshow the order is x,y,temperature, where x are latitudes and y are longitudes.

To plot the map I have written:

m = Basemap(llcrnrlon=-17,llcrnrlat=27.8,urcrnrlon=-16,urcrnrlat=28.7,resolution='i',projection='merc')


im = m.imshow(temp, cmap='BuPu')


cbi=plt.colorbar(im,shrink=0.7,format='%.1f')


plt.show()

The result is giving me:

enter image description here

But, I wanna plot only points over their location, e.g., if the point is in the coordinates x,y it should only appeared a little point over this position in the map.

Any helping hand?

Thanks!

1 Answers

Check this code:

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

df = pd.read_csv('data.csv')

m = Basemap(llcrnrlon = -17, llcrnrlat = 27.8, urcrnrlon = -16, urcrnrlat = 28.7, resolution = 'i', projection = 'merc')
m.drawcoastlines(color = 'black')

x, y = m(list(df['x']), list(df['y']))
m.scatter(x, y,
          c = df['temperatura'],
          s = 100,
          cmap = 'RdBu_r')

plt.colorbar()
plt.show()

which gives this map:

enter image description here

You used imshow(), but this funciton is useful for plotting image from a NxM matrix, so you will always get a colored rectangle, as in you purple image.
You have data in a x-y (lon-lat) coordinate format, so you could plot a scatterplot, showing the temperature in those point on the map, like my code does, where those temperature where measured.
If you want a distributed colored map (in techincal terms a temperature field), like this:

enter image description here

you need a distributed data like a meshgrid.

Related