2
該程序顯示沒有錯誤,但它會產生沒有任何點的空白圖。我後來希望修改此代碼,以便許多進程可以並行工作來更改共享的matplotlib散點圖。散點圖不使用管理器進行多點處理
from multiprocessing.managers import BaseManager, NamespaceProxy
from multiprocessing import Process
import matplotlib.pyplot as plt
import numpy as np
def plotter(res):
print(res.ax,res.fig)
res.ax.scatter(np.random.normal(0,20,(100,)),np.random.uniform(0,20,(100,)),s=1)
res.fig.savefig('man2.png')
class PlotClass():
fig = plt.figure()
ax = fig.add_subplot(111)
def __init__(self):
print('Test')
class MyManager(BaseManager):
pass
class MyAttProxy(NamespaceProxy):
# We need to expose the same __dunder__ methods as NamespaceProxy,
_exposed_ = ('__getattribute__', '__setattr__', '__delattr__')
MyManager.register('Plot', PlotClass,MyAttProxy)
if __name__ == '__main__':
manager = MyManager()
manager.start()
plotscat = manager.Plot()
pr = Process(target=plotter,args=(plotscat,))
pr.start()
pr.join()
plotscat.fig.savefig('fig.png')
您的解決方案沒有解決問題後。 –