Python 3.4:使用unstack和MPLS在动态地图上显示等高线图

Python 3.4:使用unstack和MPLS在动态地图上显示等高线图,python,matplotlib,contour,geopandas,Python,Matplotlib,Contour,Geopandas,我在获取要显示在传单地图顶部的等高线图时遇到问题。我相当肯定这是因为我不知道如何告诉MPL我的等高线图在地图上的方向。所以,问题是如何做到这一点 下面,我根据这里的代码构建了以下简单示例: 虽然这个例子的作者已经确定了他的坐标参考系,但我无法这样做。例如: import matplotlib.pyplot as plt import mplleaflet import pandas as pd # Fictional lon/lat data in pandas data frame: df

我在获取要显示在传单地图顶部的等高线图时遇到问题。我相当肯定这是因为我不知道如何告诉MPL我的等高线图在地图上的方向。所以,问题是如何做到这一点

下面,我根据这里的代码构建了以下简单示例:

虽然这个例子的作者已经确定了他的坐标参考系,但我无法这样做。例如:

import matplotlib.pyplot as plt
import mplleaflet
import pandas as pd

# Fictional lon/lat data in pandas data frame:
df= {'Lat': pd.Series([40.0,40.0,40.0,41.0,41.0,41.0,42.0,42.0,42.0]),
     'Lon': pd.Series([-69.0,-70.0,-71.0,-69.0,-70.0,-71.0,-69.0,-70.0,-71.0]),
     'Val': pd.Series([0,1,2,0,1,0,2,2,1])}
 df=pd.DataFrame(df)

#Change indices, unstack, and sort:
df.set_index(['Lat','Lon'],inplace=True)
df=df.unstack()
df.sort_index(axis=0,inplace=True)
df.sort_index(axis=1,inplace=True)

#Extract data, make a contour plot
g=df['Val']
plt.contour(g.columns.values,g.index.values,g)

#Define the crs - completely wrong I know, but what to do?
crs= {'lon_0': -105.0,
      'lat_ts': 60.0,
      'R': 6371200,
      'proj': 'stere',
      'units': 'm',
      'lat_0': 90.0}
现在,毫不奇怪,当我执行命令时:

mplleaflet.show(crs=crs)
一张空白的世界地图突然出现——我的等高线图找不到了。当然,这很可能是因为我的
crs
定义不正确。是否有人知道如何进行这项工作,甚至知道如何在python中设置参数。我还可以补充一点,实际上没有关于如何实现这一点的Python文档

最好的

马特


p、 我在Windows 7中运行Python 3.4,但我也无法获得该示例。

使用geopandas创建正确的投影:

import geopandas
from shapely.geometry import Point

s = geopandas.GeoSeries([Point(4.42, 50.4), Point(4.43, 50.2)])

s.crs = {'init': 'epsg:4326', 'no_defs': True}

s.to_crs(epsg=31370)
结果:

0     POINT (153643.9201303074 121012.188949639)
1    POINT (154373.4245113489 98766.94731544051)
dtype: object