import matplotlib.pyplot as plt
# define window size, output and axes
fig, ax = plt.subplots(figsize=[8,6])
# set plot title
ax.set_title("Some title")
# set x-axis name
ax.set_xlabel("X-Label")
# set y-axis name
ax.set_ylabel("Y-Label")
# create histogram within output
N, bins, patches = ax.hist(data, bins=50, color="#777777") #initial color of all bins
# Iterate through all histogram elements
# each element in this interation is one patch on the histogram, where:
# - bin_size - number of records in current bin
# - bin - value of current bin (x-axis)
# - patch - a rectangle, object of class matplotlib.patches.Patch
# more details on patch properties: [visit this link][1]
for bin_size, bin, patch in zip(N, bins, patches):
if bin_size == <some number>:
patch.set_facecolor("<some color like #FF000>")
patch.set_label("something")
plt.show()
与其直接调用
plt.hist
,不如尝试使用subplot
,并在其中绘制直方图,如下所示-相关问题 更多 >
编程相关推荐