在matplotlib-basemap中绘制颜色编码的标记 [英] Plotting color coded markers in matplotlib-basemap

查看:310
本文介绍了在matplotlib-basemap中绘制颜色编码的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在地图上绘制以下变量:Lons,经度列表,Lats,纬度列表和 Vals,每个位置的值列表.

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')

问:我如何最好地将我的 Vals 转换为颜色列表(热图),以传递给 scatter ,因此每个x,y 对获取匹配颜色的值?

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.

我可能会遍历我的整个 LatsLonsVals,但考虑到底图有多慢,我宁愿避免这种情况.我已经需要绘制大约 800 张地图,而将其增加到大约 100 万张可能需要数年时间.

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.

推荐答案

pyplot.scatter文档,您可以在其中找到参数 c(重点是我的):

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

c : 颜色或颜色序列,可选,默认

c : color or sequence of color, optional, default

c 可以是单个颜色格式字符串,也可以是长度为 N 的颜色规范序列,或使用 cmap 映射到颜色的 N 个数字序列和通过 kwargs 指定的规范(见下文).请注意,c不应为单个数字RGB或RGBA序列,因为这与要进行颜色映射的值数组是无法区分的.然而,c 可以是一个二维数组,其中的行是 RGB 或 RGBA.

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.

因此,如果您只是将 vals 传递给c,则matplotlib应该将值转换为标准颜色图或colorbar

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.

示例代码:

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()

这篇关于在matplotlib-basemap中绘制颜色编码的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆