Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 散点图未使用多处理管理器打印_Python_Matplotlib_Plot_Python Multiprocessing - Fatal编程技术网

Python 散点图未使用多处理管理器打印

Python 散点图未使用多处理管理器打印,python,matplotlib,plot,python-multiprocessing,Python,Matplotlib,Plot,Python Multiprocessing,这个程序没有显示错误,但它生成了一个没有任何点的空白图。稍后,我希望修改此代码,以便许多进程可以并行工作以更改共享matplotlib散点图 from multiprocessing.managers import BaseManager, NamespaceProxy from multiprocessing import Process import matplotlib.pyplot as plt import numpy as np def plotter(res): prin

这个程序没有显示错误,但它生成了一个没有任何点的空白图。稍后,我希望修改此代码,以便许多进程可以并行工作以更改共享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')

也许你应该在添加散射后重新绘制图形

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.canvas.draw_idle()
    res.fig.savefig('man2.png')

你的解决方案并不能解决问题。