首页 > 解决方案 > matplotlib:如何从直方图条中获取颜色(或 facecolor)?

问题描述

我有一个使用列表作为数据源的直方图,我想获取每个条形的颜色或 facecolor 以诊断问题。

patches.facecolor()不适合我。

#The histogram
n, bins, patches = ax.hist([lst_outliers, lst_standard], num_bins, rwidth=0.8, color=['red','blue'])

#This is how I'm trying to access the facecolor attribute of ax.patches:
patches[0][21].get_facecolor()

#It yields the following for all bars; I can't tell if this is some kind of color code:
(1.0, 0.0, 0.0, 1.0)

#Ultimately, I would like to build on the following to diagnose another problem (some day soon I will write list comps): 

for i, each_bin in enumerate(bins):
    print(str(i+1) + " " + str(each_bin))

标签: matplotlibhistogramaxesgetcolor

解决方案


推荐阅读