如何在Matplotlib中删除/更新特定Axes中的“艺术家”?

时间:2017-11-19 10:09:08

标签: python python-2.7 class matplotlib

我写了一个函数,用plt.plotplt.fillclass plotPatterns(object): def __init__(self, dataarr, ax=None): # read-in parameters and check if is valid self.ax = self._check_ax(ax) self.fig = self.ax.figure self.data = dataarr # ...initialize of other parameters self._plotting(reload_init=0) def _check_ax(self, ax=None): # check if there is a specified Axe, create one if not if ax is None: fig = plt.figure() ax = fig.add_subplot(111) return ax def _plotting(self, reload_init=0): # ...caculations with self.data #lines = self.ax.plot(x, y,) #fills = self.ax.fill(datafill_x, y,) #setxb = self.ax.set_xlim([min(self.trace_offset) - 2 * self.trace_scale, # max(self.trace_offset) + 2 * self.trace_scale]) #setyb = self.ax.set_ylim([self.t_end, self.t_start])

在指定的Ax上绘制一些线条和图案

简化代码如下:

_wiggle_plotting

如您所见, reload_init = 0 选项位于函数_wiggle_plotting(reload_init=1)中。 我想到的情景是:

如果用户在类中更新了参数并手动调用了wp = plotPatterns(data1, ax) wp.data = data1_filtered wp.plotPatterns._plotting(1) ,例如:

_wiggle_plotting

应该执行以下步骤:

  1. 删除在plt.cla()之前调用中完成的所有更改,并防止更改其他人
  2. 重做绘图部分
  3. 由于在这种情况下我不能使用 def __init__(self, dataarr, ax=None): # ...paras initialize self.plot_record = [] def _wiggle_plotting(self, reload_init=0): if reload_init==1: # ...remove all artist stored in the last list of self.plot_record self.plot_record.remove(self.plot_record[-1]) # ...caculations # ...plottings self.plot_record.append([lines, fills, setxb, setyb]) ,我正在考虑分配一个新变量,如:

    def login_data(username, password, csrf_token):
        def encrypt(text):
            m = hashlib.sha256()
            m.update(text)
            return base64.b64encode(m.hexdigest())
    
        password_hash = encrypt(username + encrypt(password) + csrf_token)
        return '<?xml version:"1.0" encoding="UTF-8"?><request><Username>admin</Username><Password>'+password_hash+'</Password><password_type>4</password_type></request>'
    

    因此,我遇到的问题是:

    1. 这看起来有点愚蠢......我的逻辑在这里做什么? 或者是否有任何先进的方法可以执行?
    2. 我不知道如何有效地删除所有艺术家。是否有一个功能我可以一劳永逸地删除指定的艺术家?
    3. 最后,如果我使用“艺术家”一词错误,请纠正我。

0 个答案:

没有答案