python - matplotlib 中不显示多边形上的点(散点)
问题描述
我想使用 matplotlib 绘制一些(简单的)多边形并在其上绘制一些点。多边形没问题,但散点不显示。有什么建议可以解决/纠正这个问题吗?
# imports
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
# polygons
gg = {'municipality 1': [(1, 1), (2, 5), (3, 3), (2, 0)],
'municipality 2': [(3, 4), (4, 6), (5, 8), (6, 3)],
'municipality 3': [(2, 0), (3, 3), (3, 4), (6, 3), (4, -3)]}
# points / places
gh = {'municipality 1': (4, 2), 'municipality 2': (2, 2), 'municipality 3': (5, 5)}
# set colors
gk = {'municipality 1': 'royalblue', 'municipality 2': 'tomato', 'municipality 3': 'springgreen'}
# figure
fig, ax = plt.subplots()
for gemeente in gg.keys():
poly = Polygon(gg[gemeente], label=gemeente, facecolor=gk[gemeente], edgecolor='black', linewidth=1)
ax.add_patch(poly)
for gemeente in gh.keys():
ax.scatter(gh[gemeente][0], gh[gemeente][1], c='black', label=gemeente)
ax.legend()
plt.autoscale()
plt.show()
解决方案
推荐阅读
- javascript - 如何使用 redux 处理竞争条件
- php - Post 请求中数组的 PHP 代码 - 改造
- r - 删除最低数值
- javascript - Google Sheet API:“消息”:“请求缺少有效的 API 密钥。”
- html - 更改背景图像大小,但不更改背景颜色
- c++ - 在函数 C++14 中包含 STL 头文件
- php - PHP 服务器到服务器窗口 XAMPP 到 UBUNTU Apache
- amazon-web-services - 如果只更改一个功能,如何避免在 serverless 框架的服务器中部署所有五个功能
- python - 在保持纵横比的同时更改 matplotlib.pyplot.imshow 中的轴
- java - 尝试更改时出现设置构建路径错误