Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.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
pickleplotpython_Python_Matplotlib_Plot_Pickle - Fatal编程技术网

pickleplotpython

pickleplotpython,python,matplotlib,plot,pickle,Python,Matplotlib,Plot,Pickle,我有一个空的绘图,可以在绘图上标记点。我可以对绘图进行pickle处理,并且我想将点保存在pickle文件中,但我希望在重新运行代码时显示已保存在pickle文件中的点。这可能吗 这是我的密码: import matplotlib from matplotlib import pyplot as plt import pickle class PointBuilder: def __init__(self, point): self.line = point

我有一个空的绘图,可以在绘图上标记点。我可以对绘图进行pickle处理,并且我想将点保存在pickle文件中,但我希望在重新运行代码时显示已保存在pickle文件中的点。这可能吗

这是我的密码:

import matplotlib
from matplotlib import pyplot as plt
import pickle

class PointBuilder:
    def __init__(self, point):
        self.line = point

        self.xs = list(point.get_xdata())

        self.ys = list(point.get_ydata())

        self.cid = point.figure.canvas.mpl_connect('button_press_event', self)

        file_name = "sample.pkl"

        open_file = open(file_name, "wb")
        pickle.dump(self.xs, open_file)
        open_file.close()

        open_file = open(file_name, "rb")
        loaded_list = pickle.load(open_file)
        open_file.close()
        print(loaded_list)


    def __call__(self, event):
        print('click', event)

        if event.inaxes!=self.line.axes: return

        self.xs.append(event.xdata)

        self.ys.append(event.ydata)

        self.line.set_data(self.xs, self.ys)

        self.line.figure.canvas.draw()


    def check_function(self, event):
        



def save(event):
    if event.key == 's':
        print ('Saved figure')
        event.canvas.figure.savefig('temp.png')


fig = plt.figure()

ax = fig.add_subplot(111)

ax.set_title('click to build line segments')

fig.canvas.mpl_connect('key_press_event', save)

punkt, = ax.plot([], [], marker="o", ms=10, ls="") # empty line

linebuilder = PointBuilder(punkt)

plt.show()