IceCube092 Asked:2020-02-13 15:36:50 +0000 UTC2020-02-13 15:36:50 +0000 UTC 2020-02-13 15:36:50 +0000 UTC Matplotlib 直方图颜色 772 过0时如何改变直方图的颜色? python 2 个回答 Voted Best Answer passant 2020-02-13T16:24:56Z2020-02-13T16:24:56Z import matplotlib.pyplot as plt import numpy as np s = np.random.normal(0, 100, 10000) n, bins, patches= plt.hist(x=s, bins='auto', color='orange') for bn, pt in zip(bins, patches): if bn<=0: pt.set_facecolor("b") 同样,您至少可以分别为每个 bin 着色。 IceCube092 2020-02-13T15:57:37Z2020-02-13T15:57:37Z colors = ['blue' if i > 0 else 'red' for i in y] ax.bar(x, y, color=colors)
同样,您至少可以分别为每个 bin 着色。