I have the following variables, that I want to plot on a map:
Lons
, a list of longitudes, Lats
, a list of latitudes and Vals
, a list of values for each location.
To plot the locations, I do a simple
x,y=Mymap(Lons,Lats)
Mymap.scatter(x,y,marker='o',color='red')
Q: how do i best turn my Vals
into a list of colors (heatmap) to be passed intoscatter
, so that every x,y
pair gets its values matching color?
The basemap docs are rather lacking, and none of the examples fits my purposes.
I could probably loop through my whole Lats
, Lons
and Vals
but given how slow basemap is, I'd rather avoid that. I already have to draw about 800 maps, and increasing that to about 1 Million will probably take years.
The basemap scatter documentation simply refers to the pyplot.scatter documentation, where you can find the parameter c (emphasis mine):
So if you simply pass
vals
to c, matplotlib should convert the values to colors on the standard colormap or a chosen colormap. To show which color is mapped to what value you can use the colorbar.Example code: