multiprocessing show matplotlib plot

前端 未结 1 1490
南笙
南笙 2020-12-18 09:08

I\'m trying to open up multiple plots but I ran into a few problems. When I tried to create plots using threading, python would first open a number of windows, then close al

相关标签:
1条回答
  • 2020-12-18 09:25

    The following code produces two figures as desired.

    import matplotlib.pyplot as plt
    import numpy as np
    
    import multiprocessing
    #multiprocessing.freeze_support() # <- may be required on windows
    
    def plot(datax, datay, name):
        x = datax
        y = datay**2
        plt.scatter(x, y, label=name)
        plt.legend()
        plt.show()
    
    def multiP():
        for i in range(2):
            p = multiprocessing.Process(target=plot, args=(i, i, i))
            p.start()
    
    if __name__ == "__main__": 
        input('Value: ') 
        multiP()
    
    0 讨论(0)
提交回复
热议问题