python - 在 matplotlib-basemap 中绘制颜色编码标记

标签 python matplotlib matplotlib-basemap

我有以下变量,我想在 map 上绘制它们: Lons,经度列表;Lats,纬度列表;Vals,每个位置的值列表。

为了绘制位置,我做了一个简单的

x,y=Mymap(Lons,Lats)
Mymap.scatter(x,y,marker='o',color='red')

问:我如何最好地将我的 Vals 转换为要传递到scatter 的颜色列表(热图),以便每个x,y 对的值与颜色匹配吗?

basemap 文档相当缺乏,并且没有一个示例符合我的目的。

我可能可以循环遍历整个LatsLonsVals,但考虑到 basemap 有多慢,我宁愿避免这样做。我已经需要绘制大约 800 张 map ,将其增加到大约 100 万张可能需要数年时间。

最佳答案

basemap scatter documentation只是指 pyplot.scatter documentation ,您可以在其中找到参数c(强调我的):

c : color or sequence of color, optional, default

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 应该将这些值转换为标准颜色图或 chosen colormap 上的颜色。 。要显示哪种颜色映射到什么值,您可以使用 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()

关于python - 在 matplotlib-basemap 中绘制颜色编码标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29146662/

相关文章:

python - 使用格式打印多个列表

python - Keras 生成模型不准确

python - 为什么我需要在此 csv 文件中添加引号?

python - basemap 和密度图

python - 如何在 FastAPI 中使用 `add_route()` 将参数传递到端点?

python - matplotlib 缺少样式模块?

python - Matplotlib自定义发散梯度忽略颜色

python - seaborn boxplot 和 stripplot 点未按色调在 x 轴上对齐

python - 未使用 Python/Basemap 在图形上绘制的线条

python - 如何在 matplotlib 中为 basemap 上的散点图制作动画?