Multiple `subplot2grid` in a for loop

前端 未结 1 1017
离开以前
离开以前 2021-01-24 22:59

I am trying to plot two different sets of functions going once through a double loop. I don\'t know how I can ask subplot2grid to act on the second figure.

impo         


        
1条回答
  •  故里飘歌
    2021-01-24 23:15

    You should use the object-oriented interface. Here is an example:

    import numpy as np
    from matplotlib import pyplot as plt
    
    t = np.linspace(0, 1, 100)
    fig1, axes1 = plt.subplots(3, 3)
    fig2, axes2 = plt.subplots(3, 3)
    
    blue, red = "#1E90FF", "#FF6347"
    for i in range(3):
        for j in range(3):
            axes1[i, j].plot(t, np.sin((t * np.random.random() * 10)), blue)
            axes2[i, j].plot(t, np.cos((t * np.random.random() * 10)), red)
    
    fig1.tight_layout()
    fig2.tight_layout()
    

    enter image description here enter image description here

    0 讨论(0)
提交回复
热议问题