我写了一个生成不同尺寸的矩形的Python代码。但是,我无法使edgecolor与facecolor相匹配。以下是我的代码的相关部分:Matplotlib的PatchCollections与set_array:如何匹配脸部颜色和边缘颜色?
# Mapping row information to geometry and color of plot points
x = np.array(info[0])-time
y = np.array(info[1])
x_width = np.array(info[2])
y_width = np.array(info[3])
colors = np.array(info[4])
colors = np.log10(colors)
patches = []
# Save rectangle object-datapoints to patches
(time_min,time_max) = (x-x_width/2., x+x_width/2.)
(freq_min, freq_max) = (y-y_width/2., y+y_width/2.)
for i in range(len(x)):
f_min_plot = max(freq_min[i],f_min)
patches.append(Rectangle((time_min[i], f_min_plot), x_width[i], freq_max[i]-f_min_plot))
fig = pl.figure()
pl.rc('text', usetex=True)
ax = fig.add_subplot(111)
p = PatchCollection(patches, match_original=False)
p.set_array(colors)
ax.add_collection(p)
cbar = pl.colorbar(p)
#cbar.set_label('$\log_{10}$ SNR', rotation = 270)
pl.xlabel("Time-%.1f" %(time))
pl.ylabel("Frequency")
pl.semilogy()
pl.title("%s1 omicron triggers"%(detector))
pl.xlim(-time_interval,time_interval)
pl.ylim(20,2000)
pl.savefig("%s/%s1-omicron-trigs-%.1f-%d.png" %(file_path, detector, time, time_interval))
此代码生成具有黑色边框的默认矩形facecolors。我需要边框颜色来匹配facecolor。请注意,我试图删除edgecolor =“none”的边框。不幸的是,这使得看到一些矩形(宽度较小的矩形)的颜色相当困难。我也尝试在Rectangle()语句中添加color = matplotlib.cm.jet(color_norm [i]#color_norm是“标准化”颜色数组:color/max(color))(当然,在PatchCollections中match_original = True ()语句)。但那也行不通。在我看来,set_array()最终决定了颜色。我无法找到关于set_array究竟做什么以及如何使用它的详细文档。
有没有什么办法让这个代码绘制出具有相同的人脸颜色和边缘颜色的矩形?我衷心感谢在这个问题上的任何帮助。