Python 如何在使用matplotlib打印geopandas数据帧时添加附加点位置

Python 如何在使用matplotlib打印geopandas数据帧时添加附加点位置,python,matplotlib,geopandas,Python,Matplotlib,Geopandas,我正在使用以下代码在geopandas数据帧的matplotlib图的顶部绘制额外的坐标/点。然而,正如图中所示,该点并未与choropleth重叠——应该重叠,因为纬度和经度位于从人口普查中获得数据的地理位置内。请告知 from cenpy import products import pandas as pd import matplotlib.pyplot as plt import geopandas %matplotlib inline tustin = products.ACS(2

我正在使用以下代码在geopandas数据帧的matplotlib图的顶部绘制额外的坐标/点。然而,正如图中所示,该点并未与choropleth重叠——应该重叠,因为纬度和经度位于从人口普查中获得数据的地理位置内。请告知

from cenpy import products
import pandas as pd
import matplotlib.pyplot as plt
import geopandas
%matplotlib inline

tustin = products.ACS(2018).from_county('Orange County, CA', level='tract',
                                        variables=['B23025_005E', 'B23025_003E'])
tustin['pct_unemployed'] = tustin.B23025_005E / tustin.B23025_003E * 100
print(tustin.crs)

# additional data co-ordinate
lat = 3374569.5
lon = -11782886.0
df = pd.DataFrame(
    {'Place': ['X'],
     'Latitude': [lat],
     'Longitude': [lon]})

gdf = geopandas.GeoDataFrame(
    df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude))

# setting the same crs as the main geopandas dataframe
gdf.crs = {'init': 'epsg:3857'}

# plot the first dataframe 'tustin' as a choropleth
f, ax = plt.subplots(1,1,figsize=(20,20))
tustin.dropna(subset=['pct_unemployed'], axis=0).plot('pct_unemployed', ax=ax, cmap='plasma')
ax.set_facecolor('k')
gdf.plot(ax=ax, color='red')
#ax.plot(-13144890.450, 3992372.350, "ro")
plt.show()

您确定该点应该重叠吗?(您是如何获得这些坐标的?)能否显示
tustin.total_bounds
的输出?(这可以告诉数据帧坐标的总边界,以检查该点是否确实与之重叠)非常感谢@joris。这里是我所看到的total_界限:数组([-13149715.043939720.19,-13070353.934021772.99])。你是对的。尽管我知道该点在cenpy结果所代表的县内的地理位置(地址),但我认为我缺少一些转换。关于如何将一对la/lon(CENTLAT':'+33.7456950',CENTLON':'-117.8288600')转换为普查返回的坐标系的任何想法。我用的是一种非常天真(而且是错误的)方法。谢谢。我想出了一个使用pypoj的方法。虽然我必须更详细地理解这一点。proj=pyproj.Transformer.from_crs(43263857,始终为_xy=True)x1,y1=(float(lon),float(lat))x2,y2=proj.transform(x1,y1)print((x2,y2))您确定该点应该重叠吗?(您是如何获得这些坐标的?)能否显示
tustin.total_bounds
的输出?(这可以告诉数据帧坐标的总边界,以检查该点是否确实与之重叠)非常感谢@joris。这里是我所看到的total_界限:数组([-13149715.043939720.19,-13070353.934021772.99])。你是对的。尽管我知道该点在cenpy结果所代表的县内的地理位置(地址),但我认为我缺少一些转换。关于如何将一对la/lon(CENTLAT':'+33.7456950',CENTLON':'-117.8288600')转换为普查返回的坐标系的任何想法。我用的是一种非常天真(而且是错误的)方法。谢谢。我想出了一个使用pypoj的方法。虽然我必须更详细地理解这一点。proj=pyproj.Transformer.from_crs(43263857,始终为_xy=True)x1,y1=(float(lon),float(lat))x2,y2=proj.transform(x1,y1)打印((x2,y2))