[英]How to set the edge color of polygon patch in matplotlib
我设法将多边形补丁渲染到 matplotlib 画布上。
在下面的代码中, node_coods
是一个包含多边形顶点的 Nx2 numpy 数组。
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
polygon = Polygon(node_coods, closed=True, edgecolor='r')
patches = [polygon]
p = PatchCollection(patches, cmap=mpl.cm.jet, alpha=0.4)
ax.add_collection(p)
目前我的情节看起来像这样,注意它没有边缘颜色,尽管传递了手册中给出的参数。 如何设置多边形补丁的边缘颜色? 我想将其设置为红色,(但我想稍后将其调整为任何 RGB 值)
既然你这样做
p = PatchCollection(patches, alpha=0.4)
根据文档, edgecolors
默认为None
,它被matplotlib.rcParams
默认设置覆盖,这是透明的。 所以要么做:
p = PatchCollection(patches, edgecolor='r', alpha=0.4)
ax.add_collection(p)
这使
或者只是使用add_patch
:
polygon = Polygon(node_coods, closed=True, edgecolor='r')
# patches = [polygon]
# p = PatchCollection(patches, alpha=0.4)
fig, ax = plt.subplots()
ax.add_patch(polygon)
这使:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.