Specifying the order of matplotlib layers

前端 未结 3 1321
感情败类
感情败类 2020-12-01 05:59

Suppose I run the following script:

import matplotlib.pyplot as plt

lineWidth = 20
plt.figure()
plt.plot([0,0],[-1,1], lw=lineWidth, c=\'b\')
plt.plot([-1,1         


        
3条回答
  •  时光说笑
    2020-12-01 06:47

    The layers are stacked from bottom to top in the same order of the corresponding calls to the plot function.

    import matplotlib.pyplot as plt
    
    lineWidth = 30
    plt.figure()
    
    plt.subplot(2, 1, 1)                               # upper plot
    plt.plot([-1, 1], [-1, 1], lw=5*lineWidth, c='b')  # bottom blue
    plt.plot([-1, 1], [-1, 1], lw=3*lineWidth, c='r')  # middle red
    plt.plot([-1, 1], [-1, 1], lw=lineWidth, c='g')    # top green
    
    plt.subplot(2, 1, 2)                               # lower plot
    plt.plot([-1, 1], [-1, 1], lw=5*lineWidth, c='g')  # bottom green
    plt.plot([-1, 1], [-1, 1], lw=3*lineWidth, c='r')  # middle red
    plt.plot([-1, 1], [-1, 1], lw=lineWidth, c='b')    # top blue
    
    plt.show()
    

    It clearly emerges from the figure below that the plots are arranged according to the bottom first, top last rule.

提交回复
热议问题