如何在matplotlib中设置轮廓标签的背景色? [英] how to set the background color of contour labels in matplotlib?
问题描述
我正在使用命令:
axins.clabel(c,levls,fontsize = 4,fmt ='%4.2f',colors ='white')
要为我的轮廓生成标签,我希望它们是带有红色背景的白色(colors='white' 有效),我不知道是否可以为它们指定背景颜色?
我参加聚会已经晚了几年,但是这个答案仍然在Google上出现,因此这是我受@pelson的答案启发而破解的解决方案./p>
如果您将等高线图设置为:
CS = ax.contour(X,Y,Z)clabels = ax.clabel(CS)
然后你可以简单地使用
更新背景颜色 [clabels中的txt的txt.set_backgroundcolor('white')]
然而,边界框 (bbox
) 非常大并且经常不必要地遮蔽其他特征.所以最好直接更新bbox
:
[txt.set_bbox(dict(facecolor ='white',edgecolor ='none',pad = 0))for clabels中的txt]
I'm using the command :
axins.clabel(c, levls, fontsize=4, fmt='%4.2f', colors= 'white')
to generate labels for my contours, I'd like them to be white (colors='white' works) with a red background, I can't find whether it's possible or not to specify a background color for them ?
I am several years late to the part party, but this answer is still coming up on Google so here is the solution I hacked inspired by @pelson's answer.
If you set up the contour plot as:
CS = ax.contour(X, Y, Z)
clabels = ax.clabel(CS)
Then you can simply update the background colours using
[txt.set_backgroundcolor('white') for txt in clabels]
However the bounding box (bbox
) is quite large and often obscures other features unnecessarily. So it is better to update the bbox
directly:
[txt.set_bbox(dict(facecolor='white', edgecolor='none', pad=0)) for txt in clabels]
这篇关于如何在matplotlib中设置轮廓标签的背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!