简体   繁体   English

如何制作动画地理热图?

[英]How to make an animated geographic heat map?

I have a list of coordinates and timestamps spread over a 24-hour period. 我有一个分布在24小时内的坐标和时间戳的列表。 I want to create an animated heat map which will show the map throughout the day. 我想创建一个动画的热图,它将全天显示该图。

I've tried looking at Basemap's example gallery but the code seems a little too complex for me to come up with even a basic heat map. 我尝试查看Basemap的示例库,但是代码对于我来说似乎有点太复杂,甚至无法提供基本的热图。 What I don't understand specifically is the data parameter of the contourf() function. 我不特别了解的是contourf()函数的data参数。

How do I proceed? 我该如何进行?

PS: Sample data: PS:样本数据:

[{'date': datetime.datetime(2013, 3, 12, 6, 13, 0), 'loc': (46.448269, 16.363296)},
 {'date': datetime.datetime(2013, 3, 12, 6, 13, 1), 'loc': (37.702152, -120.127964)},
 {'date': datetime.datetime(2013, 3, 12, 6, 13, 1), 'loc': (14.484318, 121.037639)},
 ...]

data is the data you want the contours to represent. data是您希望轮廓表示的数据。 To draw contours, you are associating a value z with each (x, y) point on your map. 要绘制轮廓,需要将值z与地图上的每个(x,y)点相关联。 data is z. data是z。 For instance, if you wanted to make a contour map of temperatures, data would be the temperatures. 例如,如果要绘制温度等高线图,则data就是温度。

Given your sample data, I don't understand what you want to plot. 根据您的样本数据,我不了解您要绘制的内容。 You have timestamps and locations, but no data associated with those values. 您具有时间戳和位置,但是没有与这些值关联的数据。 It doesn't make sense to plot a contour with just that (unless you have only one timestamp per location, and you want to plot a single, static map with the time as the z value). 仅用该轮廓绘制轮廓是没有意义的(除非每个位置只有一个时间戳,并且要以时间为z值绘制单个静态地图)。 You can't just have "an animated contour map throughout the day", you need to have an animated contour map of something (ie, some other quantity) throughout the day. 您不仅可以拥有“一整天的动画轮廓图”,还需要一整天的东西 (即其他数量)的动画轮廓图。 What do you want the values displayed on the map to represent? 您希望地图上显示的值代表什么? What is your dependent variable? 你的因变量是什么?

If you want the variable to be "number of data points at these coordinates", then you should calculate that first. 如果希望变量为“这些坐标处的数据点数”,则应首先进行计算。 That is, group your data by coordinates/time and count the number of data points at each place/time. 也就是说,将数据按坐标/时间分组并计算每个位置/时间的数据点数。 You want the equivalent of a table like: 您想要一个像这样的表:

X    Y   Time   Points
-10  2   10:30  4
-10  2   11:00  10
4    -10 10:30  6
4    -10 11:00  8

You can then generate a series of contour maps where your data variable is taken from the "Points" column. 然后,您可以生成一系列等高线图,其中data变量是从“点”列中获取的。 I'd recommend you look at the pandas library for convenient ways of slicing and aggregating the data (eg, to group by coordinates and/or time). 我建议您查看pandas库,以了解切片和汇总数据的便捷方法(例如,按坐标和/或时间分组)。

An alternative possibility is to use the technique described here . 另一种可能性是使用此处描述的技术。

As the documentation suggest, try reading the explanation of matplotlib.pyplot.contourf for details on the data paramemter. 如文档所示,请尝试阅读matplotlib.pyplot.contourf的解释以获取有关数据参数的详细信息。 The code look complicated just because it is loading geografical data from the net. 该代码看起来很复杂,因为它是从网络中加载地理信息。 and drawing both continents and seas and meridians. 并绘制大洲,海洋和子午线。

I'm a little rusty in the Basemap usage, but the core function calls (given the example in the page) are: 我对底图的使用有些生疏,但是核心功能调用(鉴于页面中的示例)为:

# create the map, i.e. the plot surface as a map projection given
# the type of projection you need and the point you want as center of the map
map = Basemap(projection='ortho', lat_0=45, lon_0=-100, resolution='l')

# draw the continents lines
map.drawcountries(linewidth=0.25)

# draw the contour plot
cs = map.contour(x, y, data, 15, linewidths=1.5)

Guess it can't be much easier than that. 猜猜没有比这容易的多了。 If you nedd a more detailed solution, please share the details of your problem, the data structure that you have and some code that you have tried. 如果需要更详细的解决方案,请共享问题的详细信息,所拥有的数据结构以及已尝试的一些代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM