matplotlib facecolor多种颜色都是黑色的

时间:2014-02-10 11:11:07

标签: python colors matplotlib

为了绘制彼此不同的几条负载曲线,准备函数plot_loads以在fill_between之间生成随机颜色。不会产生不同颜色的预期结果。无法发现错误?求助。

def plot_loads(ti, tf, loads, max_y):
     """ 
     plot load curves

     \param ti : init t
     \param tf : final t
     \param loads : list of load curve lists
                   loads = [[ load1], [load2], ...]
     \param max_y : vertical limit."""

    #imports
    from matplotlib import pyplot as plt
    import numpy as np
    import random

    ys_array = []

    for item in loads:
        ys_array.append(item)

    y = np.row_stack(ys_array)  
    x = np.arange(ti, tf)

    y_stack = np.cumsum(y, axis=0)

    fig = plt.figure(random.randint(1,1000))
    #plot frame positioning
    ax1 = fig.add_subplot(211) 

    #plot maximum load
    ax1.fill_between(x, 0, max_y, alpha=0.1, facecolor = 'black')

    #
    for i, item in enumerate(loads):
        if i  == 0:
            ax1.fill_between( x, 0, y_stack[0,:], facecolor = random.choice(['g', 'r', 'c', 'm', 'y', 'k']))
        else:
            ax1.fill_between( x, y_stack[i-1,:], y_stack[i,:], facecolor =random.choice(['g', 'r', 'c', 'm', 'y', 'k']))

    plt.show()

1 个答案:

答案 0 :(得分:0)

希望下面的数字能很好地说明答案。 丢弃熟人的第二个子情节。

  1. 窗口尚未扩展。
  2. enter image description here

    1. 展开或缩放窗口,颜色变为可见。 enter image description here

    2. 在fill_between之间指令linewidth = 0.0,[求助]

    3. enter image description here