如何绘制一个复杂的多边形? [英] How to plot a complex polygon?

查看:61
本文介绍了如何绘制一个复杂的多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 GIS 数据库读取数据并使用 mpl_toolkits.basemap 和 matplotlib 创建地图.一些数据创建复杂的多边形(由外环和内环定义).但是,我无法追踪如何创建带孔的多边形.matplotlib甚至有可能吗?有没有其他方法可以创建这个图像?

I am reading data in from a GIS database and creating a map with mpl_toolkits.basemap and matplotlib. Some of the data creates complex polygons (defined by an exterior and interior rings). However, I haven't been able to track down how to create a polygon with holes. Is this even possible with matplotlib? Is there another method for creating this image?

推荐答案

旧问题,但是...

只需明确关闭您的外部和内部边界,然后将它们相加即可.从技术上讲,会有一个接缝,但您不会看到它(如果您提供了一个颜色参数-不确定为什么会这样).

Just explicitly close your exterior and interior boundaries and sum them together. Technically, there will be a seam, but you won't see it (IF you provide a color argument--not exactly sure why this is the case).

#!/usr/bin/env python3

import matplotlib.pyplot as plt

# a 4x4 box (counterclockwise)
ext_x = [2, -2, -2, 2, 2]
ext_y = [2, 2, -2, -2, 2]

# a 2x2 hole in the box (clockwise)
int_x = [item/2.0 for item in ext_x][::-1]
int_y = [item/2.0 for item in ext_y][::-1]

# if you don't specify a color, you will see a seam
plt.fill(ext_x+int_x, ext_y+int_y, color='blue')

plt.show()

这篇关于如何绘制一个复杂的多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆