Looping through a function to plot several subplots, Python

前端 未结 2 1963
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 07:58

I have variables x and y

def function(a,b):
    x = x[(x>a)*(xb)]

    # perform some fitting          


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-15 08:19

    The key is using the three parameter form of subplot:

    import matplotlib.pyplot as plt
    
    # Build a list of pairs for a, b
    ab = zip(range(6), range(6))
    
    #iterate through them
    for i, (a, b) in enumerate(ab):
        plt.subplot(2, 3, i+1)
        #function(a, b)
        plt.plot(a, b)
    
    plt.show()
    

    You'll just have to take the call to figure out of the function.

提交回复
热议问题