【发布时间】:2021-01-08 21:35:01
【问题描述】:
我有一个笔记本 (github link),我在其中使用 geopandas 绘制带有不同国家颜色的地图。根据绘图的顺序,有时它不尊重我指定的 figsize() 。我在 Ubuntu 20.04 和 Firefox 中本地运行的 jupyter 以及在 Chromium 中运行的 Binder 和 Colab 中反复看到这种行为。
有人可以帮助我了解发生了什么吗?这是一个错误还是我控制 geopandas/matplotlib 错误?
import matplotlib.pyplot as plt
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
sixc = world[ world['continent'] != 'Antarctica' ]
asia = world[ world['continent'] == 'Asia' ]
noam = world[ world['continent'] == 'North America']
swed = world[ world['iso_a3'] == 'SWE' ]
# This works, makes a 2x1 landscapey aspect
axes = sixc.plot(figsize=(8,4), color='lightgrey')
asia.plot(ax=axes, color='green')
noam.plot(ax=axes, color='purple')
# Plotting swed at the end breaks figsize, makes it squareish
axes = sixc.plot(figsize=(8,4), color='lightgrey')
asia.plot(ax=axes, color='green')
noam.plot(ax=axes, color='purple')
swed.plot(ax=axes, color='yellow')
# Plotting swed in the middle makes it ok again
axes = sixc.plot(figsize=(8,4), color='lightgrey')
asia.plot(ax=axes, color='green')
swed.plot(ax=axes, color='yellow')
noam.plot(ax=axes, color='purple')
(另外,对于我的一些学生(但不是全部!),这个破碎的情节也没有浅灰色背景国家。这可能是导致方面问题的任何结果/副作用吗?)
【问题讨论】:
-
geopandas 的版本是多少?运行
gpd.__version__ -
gpd.__version__ == 0.8.1
-
也就是说,这就是我笔记本电脑上的gpd版本,大概是我使用本地jupyter时正在使用的(我不做'环境')。 colab 也从 "!pip install" 获得 0.8.1
标签: python matplotlib geopandas figsize