我已经编写了一段生成不同大小矩形的Python代码。然而,我无法使边缘颜色与填充颜色相匹配。以下是我的代码中相关部分:
# 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))
这段代码生成了默认的黑边框矩形面颜色。我需要边框颜色与面颜色相匹配。请注意,我已尝试使用edgecolor =“none”删除边框。不幸的是,这使得看到一些矩形的颜色(那些宽度较小的矩形)变得更加困难。我还尝试在Rectangle()语句中添加color = matplotlib.cm.jet(color_norm [i]#color_norm是“标准化”颜色数组:color / max(color)),当然,在PatchCollections()语句中也要添加match_original = True。但那也行不通。对我来说,set_array()最终确定颜色。我无法找到关于set_array具体做什么以及如何使用它的详细文档。
有没有办法让这个代码绘制具有相同面颜色和边框颜色的矩形?非常感谢您对这个问题的任何帮助。