

class NodeAnimation(object):

	def __init__(self, data, show_trail=False):
		self.fig = plt.figure()
		self.data = data
		self.show_trail = show_trail

	def init_plot(self):
		real_coords, mds_coords, *others = next(self.data)
		self.anchors_scat = plt.scatter(real_coords[:NO_OF_ANCHORS, 0], real_coords[:NO_OF_ANCHORS, 1], color='blue', s=100, lw=1, label='Anchors positions', marker='o')
		self.real_scat = plt.scatter(real_coords[NO_OF_ANCHORS:, 0], real_coords[NO_OF_ANCHORS:, 1], color='blue', s=100, lw=1, label='Tag positions', marker='o', facecolors='none')
		self.mds_scat = plt.scatter(mds_coords[:, 0], mds_coords[:, 1], color='red', s=150, lw=2, label='Estimated positions', marker='+')
		scatterplots = self.real_scat, self.mds_scat
		if self.show_trail:
			last_n_mds_coords = others[0][2:]
			self.last_n_scat = plt.scatter(last_n_mds_coords[:, :, 0], last_n_mds_coords[:, :, 1], label='MDS iterations', color='magenta', s=0.5)
			scatterplots += (self.last_n_scat,)
		plt.legend(loc='best', scatterpoints=1, fontsize=11)
		return scatterplots
		
	def update_plot(self, _):
		real_coords, mds_coords, *others = next(self.data)
		self.real_scat.set_offsets(real_coords)
		self.mds_scat.set_offsets(mds_coords)
		scatterplots = self.real_scat, self.mds_scat
		if self.show_trail:
			last_n_mds_coords = others[0][2:]
			self.last_n_scat.set_offsets(last_n_mds_coords)
			scatterplots += (self.last_n_scat,)
		return scatterplots

	def draw_plot(self, save_to_file=False):
		anim = animation.FuncAnimation(self.fig, self.update_plot, init_func=self.init_plot, interval=300)
		

		# matplotlib bug? Not calling plt.show in the same scope as anim gives a blank figure
		axes = plt.gca()
		
		axes.set_xlabel('coordinate x [m]')
		axes.set_ylabel('coordinate y [m]')
		axes.set_xlim([-5, 35])
		axes.set_ylim([-5, 29])
		if save_to_file:
			anim.save('mds_animation_filtering.mp4', extra_args=['-vcodec', 'libx264'])
		
		plt.show()





if __name__ == '__main__':
	anc = 4
	config.NO_OF_ANCHORS = anc
	config.NO_OF_TAGS = 7
	config.ANCHORS = config.ANCHORS_[:anc]
	# config.MISSINGDATA = 'None'
	# noise = dict(mu=0, sigma=1)
	# for_plotting, for_evaluation = tee(generate_data(config, anc, '_smacof_with_anchors_single', add_noise=noise, filter_noise=False))
	# anim = NodeAnimation(for_plotting,show_trail=False)
	# anim.draw_plot()
@@ -1,8 +1,202 @@
+from matplotlib import pyplot as plt%0Afrom matplotlib import animation%0A%0Afrom core.config import Config%0Afrom utils import generate_dynamic_nodes%0A%0A# number of mobile node transitions%0ANO_TRANS = 100
 %0A%0Aclass 
@@ -238,16 +238,21 @@
 __(self,
+ cfg,
  data, s
@@ -344,16 +344,92 @@
 ow_trail
+%0A%09%09self.no_of_anchors = cfg.no_of_anchors%0A%09%09self.no_of_tags = cfg.no_of_tags
 %0A%0A%09def i
@@ -544,29 +544,34 @@
 coords%5B:
-NO_OF_ANCHORS
+self.no_of_anchors
 , 0%5D, re
@@ -581,29 +581,34 @@
 coords%5B:
-NO_OF_ANCHORS
+self.no_of_anchors
 , 1%5D, co
@@ -714,29 +714,34 @@
 _coords%5B
-NO_OF_ANCHORS
+self.no_of_anchors
 :, 0%5D, r
@@ -751,29 +751,34 @@
 _coords%5B
-NO_OF_ANCHORS
+self.no_of_anchors
 :, 1%5D, c
@@ -2236,18 +2236,16 @@
 ow()%0A%0A%0A%0A
-%0A%0A
 if __nam
@@ -2268,263 +2268,206 @@
 ':%0A%09
-anc = 4%0A%09config.NO_OF_ANCHORS = anc%0A%09config.NO_OF_TAGS = 7%0A%09config.ANCHORS = config.ANCHORS_%5B:anc%5D%0A%09# config.MISSINGDATA = 'None'%0A%09# noise = dict(mu=0, sigma=1)%0A%09# for_plotting, for_evaluation = tee(generate_data(config, anc, '_smacof_with_anchors_single'
+cfg = Config(no_of_anchors=4, no_of_tags=7, missingdata=True)%0A%09noise = dict(mu=0, sigma=1)%0A%09data = generate_dynamic_nodes(cfg, algorithm='_smacof_with_distance_recovery_single', no_of_trans=NO_TRANS
 , ad
@@ -2500,21 +2500,18 @@
 e=False)
-)
 %0A%09
-# 
 anim = N
@@ -2527,21 +2527,19 @@
 ion(
-for_plotting,
+cfg, data, 
 show
@@ -2553,18 +2553,16 @@
 False)%0A%09
-# 
 anim.dra

update config as class instance