在matplotlib中我有:
cmap = plt.cm.RdYlBu_r
colors = cmap(np.linspace(0,1, len(patches)))
collection = PatchCollection(patches, alpha=.3,
facecolor=colors, linestyle='solid')
它给了我想要的东西,除了边框继承了“alpha”属性。如何绘制具有深色边框但透明面部颜色的多边形?
答案 0 :(得分:0)
作为旁路解决方案,您可以保留构成多边形的点,并绘制连接点的线,如下面的代码所示:
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()