python直方图cumulative_python中的多重数据直方图

哈哈,问题是matplotlib正在重用颜色。所以剧情是你想要的,你只需要更多的颜色。这是我对你的代码的修改。在import matplotlib.pyplot as plt

import numpy as np

from numpy import array

bins_1=[25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170]

x=[array([ -17.39386525, 48.368168 , 79.47025691, 81.56601668,

89.18470488, 95.41711067, 100. , 101.37656251,

101.66780064]), array([ 74.01649726, 76.57421598, 83.82263397, 101.09723897,

101.35599967, 106.20473323, 125.32481435]), array([ 80.30799141, 80.69495682, 90.64266387, 100.59333806,

110.92342467, 114.03759007]), array([ 75.73950779, 82.78756325, 91.12237053, 99.16053347,

102.75900509, 111.29184111, 112.53084035]), array([ 90.76141555, 95.50630177, 98.47127058, 101.53835677,

118.05901363, 121.97579472, 123.93998025]), array([ 84.83641744, 88.25589465, 88.73029233, 90.67304666,

92.45594435, 94.53857766]), array([ 90.02129774, 97.47537826, 98.1094508 , 104.90845359,

123.88128883]), array([ 70.45117675, 86.58666341, 88.58116115, 96.40940807,

108.82477152, 119.2192689 , 121.29656905]), array([ 85.41581466, 89.11517158, 99.48923389, 105.79105149,

107.17832611, 109.12150105, 117.93740188]), array([ 84.9374751 , 86.59808353, 89.4279953 , 89.62824778,

95.06305366, 96.73698641, 97.22749937, 98.11341876,

100.59178895, 105.20938707]), array([ 59.80245368, 82.96922252, 96.88431443, 98.08075879,

99.1774299 , 101.28416133, 127.44875806]), array([ 97.39841438, 101.87313756, 103.74805137, 110.38644243,

110.73198861, 125.97443118, 134.71140893, 148.63492245]), array([ 88.60244669, 99.29194404, 99.82668617, 105.2816237 ]), array([ 91.31362803, 94.91830313, 97.50844764, 111.59560735]), array([ 79.45212159, 80.56841471, 90.74986538, 92.88847337,

94.9665391 , 100.98072459, 101.80697666, 111.38101874,

112.75886621]), array([ 17.04198007, 97.23402024, 100.54257276, 113.17293093,

114.26809621, 121.08638797, 123.64111202]),]

n, bins, patches = plt.hist(x,bins_1, histtype='bar', stacked=True, normed=1, color=['b','g','y','purple','pink','crimson','burlywood','chartreuse','magenta','firebrick','cyan','black','darkgoldenrod', 'gray','g','k' ])

plt.show()

请注意,每个颜色都已指定。在

^{pr2}$

如果您想验证这是真的发生了什么,在您自己的代码中,设置cumulative=True,您将看到颜色对齐。只有你不需要累积图,所以指定颜色可能是目前最好的选择。在

更新:

使用mpltools(你需要下载)你可以更容易地做到这一点。

要安装,如果linux只需输入sudo pip install mpltools

下面是一个可行的例子:import matplotlib.pyplot as plt

import numpy as np

from numpy import array

from mpltools import layout

from mpltools import color

bins_1=[25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170]

x=[array([ -17.39386525, 48.368168 , 79.47025691, 81.56601668,

89.18470488, 95.41711067, 100. , 101.37656251,

101.66780064]), array([ 74.01649726, 76.57421598, 83.82263397, 101.09723897,

101.35599967, 106.20473323, 125.32481435]), array([ 80.30799141, 80.69495682, 90.64266387, 100.59333806,

110.92342467, 114.03759007]), array([ 75.73950779, 82.78756325, 91.12237053, 99.16053347,

102.75900509, 111.29184111, 112.53084035]), array([ 90.76141555, 95.50630177, 98.47127058, 101.53835677,

118.05901363, 121.97579472, 123.93998025]), array([ 84.83641744, 88.25589465, 88.73029233, 90.67304666,

92.45594435, 94.53857766]), array([ 90.02129774, 97.47537826, 98.1094508 , 104.90845359,

123.88128883]), array([ 70.45117675, 86.58666341, 88.58116115, 96.40940807,

108.82477152, 119.2192689 , 121.29656905]), array([ 85.41581466, 89.11517158, 99.48923389, 105.79105149,

107.17832611, 109.12150105, 117.93740188]), array([ 84.9374751 , 86.59808353, 89.4279953 , 89.62824778,

95.06305366, 96.73698641, 97.22749937, 98.11341876,

100.59178895, 105.20938707]), array([ 59.80245368, 82.96922252, 96.88431443, 98.08075879,

99.1774299 , 101.28416133, 127.44875806]), array([ 97.39841438, 101.87313756, 103.74805137, 110.38644243,

110.73198861, 125.97443118, 134.71140893, 148.63492245]), array([ 88.60244669, 99.29194404, 99.82668617, 105.2816237 ]), array([ 91.31362803, 94.91830313, 97.50844764, 111.59560735]), array([ 79.45212159, 80.56841471, 90.74986538, 92.88847337,

94.9665391 , 100.98072459, 101.80697666, 111.38101874,

112.75886621]), array([ 17.04198007, 97.23402024, 100.54257276, 113.17293093,

114.26809621, 121.08638797, 123.64111202]),]

n_lines = len(x)

color.cycle_cmap(n_lines, cmap='cool')

n, bins, patches = plt.hist(x,bins_1, histtype='bar', stacked=True, normed=1)

plt.show()

而here是一个可以从中选择的cmap列表,here是这个答案的来源文档。在

这是用color.cycle_cmap(n_lines, cmap='Dark2')

你可能感兴趣的:(python直方图cumulative_python中的多重数据直方图)