简体   繁体   English

地理熊猫 matplotlib 上的 plot 数据

[英]plot data on Geopandas matplotlib

i want to plot x and y from a csv file in a geopandas graph but only the graph axis that shows up我想 plot x 和 y 来自 geopandas 图中的 csv 文件,但只有显示的图轴

import fiona
import matplotlib.pyplot as plt
from mpl_toolkits.axisartist.axislines import Subplot
import pandas as pd
gpd.io.file.fiona.drvsupport.supported_drivers['KML'] = 'rw'
gpd.io.file.fiona.drvsupport.supported_drivers["KML"] = "rw"
dfN = pd.read_csv ("nodes.txt",delimiter ="\\s+")
dfN.to_csv ("nodes.csv", index=None)
df = gpd.read_file("data.kml", driver="KML")
df=df.to_crs(epsg=32733)
gdf = gpd.GeoDataFrame(dfN ,geometry=gpd.points_from_xy(dfN.X, dfN.Y))
dg=df.translate(433050,299)
fig,ax = plt.subplots()
ax.set_aspect('equal')
ax.scatter(gdf.X, gdf.Y , zorder=1, alpha= 1, c='r', s=10)
dg.plot(ax=ax,zorder=0,color='white', edgecolor='black',aspect= 'equal')
plt.show()

在此处输入图像描述

  • this is not a MWE so have sourced data from publicly available and have applied same transformations...这不是 MWE,因此从公开可用的数据中获取数据并应用了相同的转换......
  • plotting code can simplified, then it works.绘图代码可以简化,然后就可以了。 using plot() on geopandas which includes POINT objects will produce a scatter在包含POINT对象的geopandas上使用plot()将产生散点图
import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
import requests, io

# data sourcing generated two geopandas data frames,  let's replace to make MWE
df = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
df=df.to_crs(epsg=32733)

dg = df.loc[df["geometry"].is_valid *df["iso_a3"].eq("GBR")].translate(433050,299)
dfN = pd.read_csv(io.StringIO(requests.get("https://assets.nhs.uk/data/foi/Hospital.csv").text),
    sep="Č",engine="python",).loc[:,["OrganisationName","Latitude","Longitude"]].rename(columns={"Latitude":"Y","Longitude":"X"})

gdf = gpd.GeoDataFrame(dfN ,geometry=gpd.points_from_xy(dfN.X, dfN.Y))
gdf = gdf.set_crs("EPSG:4326").to_crs(epsg=32733)

# plotting code is simplified as:
ax = dg.plot(zorder=0,color='white', edgecolor='black',aspect= 'equal')
gdf.plot(ax=ax, zorder=1, alpha= 1, c='r', markersize=10)

output output

  • clearly within the defined CRS, plus one set of geometry has been transformed清楚地在定义的 CRS 内,加上一组几何图形已被转换

在此处输入图像描述

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

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