我写了一个函数,用plt.plot
和plt.fill
和class 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])
简化代码如下:
_wiggle_plotting
如您所见, reload_init = 0 选项位于函数_wiggle_plotting(reload_init=1)
中。
我想到的情景是:
如果用户在类中更新了参数并手动调用了wp = plotPatterns(data1, ax)
wp.data = data1_filtered
wp.plotPatterns._plotting(1)
,例如:
_wiggle_plotting
应该执行以下步骤:
plt.cla()
之前调用中完成的所有更改,并防止更改其他人由于在这种情况下我不能使用 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>'
因此,我遇到的问题是: