ItGo.me Focus on IT Recommend

Home > python - Plotting color coded markers in matplotlib-basemap

python - Plotting color coded markers in matplotlib-basemap

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1074

【阿里云】双十一活动,全年抄底价,限时3天!(老用户也有),
入口地址https://www.aliyun.com/1111/home

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.

python matplotlib matplotlib-basemap
|
  this question
asked Mar 19 '15 at 14:02 JC_CL 322 2 14

 | 

1 Answers
1

---Accepted---Accepted---Accepted---

The basemap scatter documentation simply refers to the pyplot.scatter documentation, where you can find the parameter c (emphasis mine):

c : color or sequence of color, optional, default

Recommend:python - Plotting a map with matplotlib basemap - horribly slow

e (around 10 seconds!). This is just unreal! Setting of resolution is only "l" (low). Here is the very simple code: import matplotlibmatplotlib.use('Agg')import matplotlib.pyplot as pltfrom mpl_toolkits.basemap import Basemapm = Basem

c can be a single color format string, or a sequence of color specifications of length N, or a sequence of N numbers to be mapped to colors using the cmap and norm specified via kwargs (see below). Note that c should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. c can be a 2-D array in which the rows are RGB or RGBA, however.

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:

import matplotlib.pyplot as plt

lons = range(50)
lats = range(25, 75)
vals = range(50,100)

plt.scatter(lons, lats, c=vals, cmap='afmhot')
plt.colorbar()
plt.show()

|
  this answer
answered Mar 19 '15 at 15:15 fhdrsdg 4,001 2 13 30      Thanks, that works. I was only looking round in the main documentation, since i thought the api part was internal stuff, only useful when you want to really change stuff under the hood. –  JC_CL Mar 19 '15 at 19:04

 | 

Recommend:python - Matplotlib Basemap Plotting Lat/Lons

Matplotlib basemap plot, using the animation function. I have tried implementing this example code into my script, but all my points plot at once. It may have something to do with my function and the for loop within the function. Any thoug

------splitte line----------------------------