gpt4 book ai didi

python - 如何绘制具有深色边框但面色透明的多边形?

转载 作者:行者123 更新时间:2023-12-04 16:47:01 26 4
gpt4 key购买 nike

在 matplotlib 中我有:

cmap = plt.cm.RdYlBu_r
colors = cmap(np.linspace(0,1, len(patches)))
collection = PatchCollection(patches, alpha=.3,
facecolor=colors, linestyle='solid')

它给了我我想要的东西,除了边框继承了“alpha”属性。如何绘制具有深色边框但面色透明的多边形?

最佳答案

作为旁路解决方案,您可以保留构成多边形的点并绘制连接这些点的线,如下面的代码所示:

import matplotlib
import numpy,matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
fig = plt.figure()
axe = fig.add_subplot(111)
polyval = numpy.random.rand(4,2) # Create the sequence of 4 2D points
patches = [Polygon(polyval,True)]
p = PatchCollection(patches,cmap=matplotlib.cm.jet,alpha=0.3)
p.set_array(100.*numpy.random.rand(1)) # Set a random color on jet map
axe.add_collection(p)
fig.colorbar(p)
fig.show()
for patch in patches:
axe.add_patch(Polygon(patch.get_xy(),closed=True,ec='k',lw=3,fill=False)) #draw the contours
fig.canvas.draw()

关于python - 如何绘制具有深色边框但面色透明的多边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40351969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com