如何获得传奇

发布于 2025-02-13 11:23:47 字数 640 浏览 0 评论 0原文

我正在尝试用Shapefiles绘制一些数据,但是我需要一个传奇来区分哪种shapefile在哪种颜色上。我为每个shapefile分配了颜色,但棘手的部分是创建一个传奇。

我的代码如下:

data = gpd.GeoDataFrame(data, geometry=gpd.points_from_xy(data.INTPTLON, data.INTPTLAT))

fig, ax = plt.subplots(figsize=(10, 10))
DC_BLK.plot(ax=ax,edgecolor = "black" ,facecolor = "None")

DC_BG.plot(ax=ax, edgecolor = "lightblue",facecolor = "None")

DC_CT.plot(ax=ax,edgecolor = "purple",facecolor = "None")

data.plot(ax=ax , marker = '.')

ax.set_title('Washington DC - 7x pop')

plt.show()

数据。情节 - 使用经度&绘制三个点;纬度在地图上。 dc_blk-包含直流块的shapefile DC_BG-包含直流块组的shapefile DC_CT-包含DC人口普查区的ShapeFile

I am trying to graph some data with shapefiles, but I need a legend to distinguish which shapefile is in which color. I assigned a color to each shapefile, but the tricky part is to create a legend.

My code is below:

data = gpd.GeoDataFrame(data, geometry=gpd.points_from_xy(data.INTPTLON, data.INTPTLAT))

fig, ax = plt.subplots(figsize=(10, 10))
DC_BLK.plot(ax=ax,edgecolor = "black" ,facecolor = "None")

DC_BG.plot(ax=ax, edgecolor = "lightblue",facecolor = "None")

DC_CT.plot(ax=ax,edgecolor = "purple",facecolor = "None")

data.plot(ax=ax , marker = '.')

ax.set_title('Washington DC - 7x pop')

plt.show()

data. plot - plots three points using longitude & latitude onto the map.
DC_BLK - shapefile containing DC blocks
DC_BG - shapefile containing DC block groups
DC_CT - shapefile containing DC Census tract

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间海 2025-02-20 11:23:47

我发现了。我想发布我所做的事情,以防有人遇到类似的问题。
这是我所做的:

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
data = gpd.GeoDataFrame(data, geometry=gpd.points_from_xy(data.INTPTLON, data.INTPTLAT))
fig, ax = plt.subplots(figsize=(10, 10))
DC_BLK_PLT = DC_BLK.plot(ax=ax,edgecolor = "grey", facecolor = "None")
DC_BG_PLT = DC_BG.plot(ax=ax, edgecolor = "lightblue",facecolor = "None")
DC_CT_PLT = DC_CT.plot(ax=ax,edgecolor = "black",facecolor = "None")
data.plot(ax=ax , marker = '.')
grey  = mpatches.Patch(color = 'grey', label = 'Block')
Lblue = mpatches.Patch(color = 'Lightblue', label = 'Block Group')
Black = mpatches.Patch(color= 'black', label = 'Census Tract')
ax.set_title('Washington DC - 7x pop')
plt.legend(handles = [grey,Lblue,Black])
plt.show()

希望这会有所帮助

I figured it out. I wanted to post what I did just in case someone runs into a similar problem.
Here is what i did:

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
data = gpd.GeoDataFrame(data, geometry=gpd.points_from_xy(data.INTPTLON, data.INTPTLAT))
fig, ax = plt.subplots(figsize=(10, 10))
DC_BLK_PLT = DC_BLK.plot(ax=ax,edgecolor = "grey", facecolor = "None")
DC_BG_PLT = DC_BG.plot(ax=ax, edgecolor = "lightblue",facecolor = "None")
DC_CT_PLT = DC_CT.plot(ax=ax,edgecolor = "black",facecolor = "None")
data.plot(ax=ax , marker = '.')
grey  = mpatches.Patch(color = 'grey', label = 'Block')
Lblue = mpatches.Patch(color = 'Lightblue', label = 'Block Group')
Black = mpatches.Patch(color= 'black', label = 'Census Tract')
ax.set_title('Washington DC - 7x pop')
plt.legend(handles = [grey,Lblue,Black])
plt.show()

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文