假设我有以下包含3个多边形对象的地理数据框。
import geopandas as gpd
from shapely.geometry import Polygon
p1=Polygon([(0,0),(0,1),(1,1),(1,0)])
p2=Polygon([(3,3),(3,6),(6,6),(6,3)])
p3=Polygon([(3,.5),(4,2),(5,.5)])
gdf=gpd.GeoDataFrame(geometry=[p1,p2,p3])
gdf['Value1']=[1,10,20]
gdf['Value2']=[300,200,100]
gdf
内容:
>>> gdf
geometry Value1 Value2
0 POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0)) 1 300
1 POLYGON ((3 3, 3 6, 6 6, 6 3, 3 3)) 10 200
2 POLYGON ((3 0.5, 4 2, 5 0.5, 3 0.5)) 20 100
>>>
我可以通过两次调用geopandas.plot()
为每个情节制作一个单独的数字。但是,有没有办法让我在与子图相同的图中将这两张地图彼此相邻?
答案 0 :(得分:4)
始终始终 始终 提前创建matplotlib对象并将其传递给绘图方法(或直接使用它们)。这样做,您的代码变为:
ggplot(data=dat2 , aes(x=x, y=Value, group = Metric,colour = Metric,linetype = Metric)) +
geom_line() + geom_point() + ylab("value") +
xlab("v") +
scale_x_discrete(breaks = c( seq(1,5,1) ) ) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
scale_y_continuous(breaks = c( seq(-3,3,.25) ) ) +
scale_colour_manual(values=c(mu = "blue", sd = "blue", Q1 = "red", Q3 = "red")) +
scale_linetype_manual(values =c(mu = "dashed", sd= "solid", Q1 = "solid", Q3 = "solid")) +
facet_wrap(~ group, scales = "free",ncol=3,
# add a labeller here:
labeller = as_labeller(setNames(lbl, sort(unique(group))))) +
theme(strip.text.x = element_text(size=10, angle=0),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(colour="red", fill="#CCCCFF"))
这给了我:
答案 1 :(得分:-1)
// for plotting multiple GeoDataframe
import geopandas as gpd
gdf = gpd.read_file(geojson)
fig, axes = plt.subplots(1,4, figsize=(40,10))
axes[0].set_title('Some Title')
gdf.plot(ax=axes[0], column='Some column for coloring', cmap='coloring option')
axes[0].set_title('Some Title')
gdf.plot(ax=axes[0], column='Some column for coloring', cmap='coloring option')