def delete_oldest_record(self):
     ''' delete the oldest plotting '''
     try:
         p = self.plot_record.pop(0)
         Artist.remove(p.point)
     except Exception as e:
         print e
         pass
Example #2
0
 def removeElement(self, element: Artist):
     """ remove an Artis from the figure """
     # create_key = key+".new"
     created_by_pylustrator = (element, ".new") in self.changes
     # delete changes related to this element
     keys = [k for k in self.changes]
     for reference_obj, reference_command in keys:
         if reference_obj == element:
             del self.changes[reference_obj, reference_command]
     if not created_by_pylustrator:
         self.addChange(element, ".set_visible(False)")
         element.set_visible(False)
     else:
         element.remove()
     self.figure.selection.remove_target(element)
Example #3
0
    def update_el(self, el, state):
        ''' el = TSCS.EL 
            state = STATL.TELDRIVE '''

        self.logger.debug('updating el=%s state=%s' % (str(el), state))

        val, color = self.__get_val_state(el, state)

        try:
            Artist.remove(self.el)
            el_kwargs = dict(alpha=0.5, fc=color, ec=color, lw=8)
            self.el = mpatches.Wedge((1, 0), 0.99, 180 - val, 180, **el_kwargs)
            self.axes.add_patch(self.el)
            self.draw()
        except Exception as e:
            self.logger.error('error: updating. %s' % str(e))
            pass
Example #4
0
def progress(i, y, ax1, ax2, n, test, fig):
    #    if i==1:
    #style.use('fivethirtyeight')
    #fig = plt.figure()
    #ax1 = fig.add_subplot(1,1,1)
    #plt.ylabel('convergence')
    #plt.xlabel('iteration')
    #    else:
    err_range = (np.amax(y) - np.amin(y)) / 2.0

    #ax2.cla()
    ax1.errorbar(i, np.mean(y), yerr=err_range, fmt='o')
    if i != 0:
        #Artist.remove(ax1.texts)
        #fig.text.remove()
        #print(ax1.get_extents)
        [Artist.remove(txt) for txt in ax1.texts]
    [txt.set_visible(False) for txt in ax1.texts]
    #if i != 0:
    #    textvar = ax1.texts
    #textvar.remove(True)
    #ax1.remove(textvar)
    #ax1.texts.set_visible(False)
    #    [txt.set_visible(False) for txt in ax1.texts]
    #for txt in ax1.texts:
    #txt.set_visible(False)

    text_box = AnchoredText(np.amin(y), frameon=True, loc=1, pad=0.5)
    plt.setp(text_box.patch, facecolor='white', alpha=1)
    ax1.add_artist(text_box)

    #plot_text = ax1.text(3, 9, np.amin(y),bbox=dict(facecolor='white', alpha=1))
    #plot_text._bbox_patch._mutation_aspect = 0.1
    #plot_text.get_bbox_patch().set_boxstyle("square", pad=1)

    #ax2.text(n,4,np.amin(y),bbox=dict(facecolor='white', alpha=1))

    ax2.plot(range(3), y, c=[0, 0, 0])

    #ax2.xaxis.font(12)
    ax2.tick_params(labelsize='small')

    #fig.clf()
    #ax2.draw()

    #ax2.text()
    plt.pause(0.5)  #time it waits for plot to update
Example #5
0
    def print(self):

        color = self.colors

        # Plot points
        x = [given_coordinate[0] for given_coordinate in self.positions]
        y = [given_coordinate[1] for given_coordinate in self.positions]

        sizes = [
            max(min(5000, given_weight), 50) for given_weight in self.U_values
        ]
        scatter_artist = self.ax.scatter(x,
                                         y,
                                         facecolors=['none'] * len(color),
                                         edgecolors=color,
                                         s=sizes)
        annotation_artists = [None for dummy in range(len(self.positions))]
        for i in range(len(self.positions)):
            annotation_artists[i] = self.ax.annotate(i, (x[i], y[i]))

        line_artists = [None for dummy in range(len(self.positions))]
        for i in range(len(self.positions)):
            if i is not self.choices[i]:
                point1 = [self.positions[i][0], self.positions[i][1]]
                point2 = [
                    self.positions[self.choices[i]][0],
                    self.positions[self.choices[i]][1]
                ]
                x_values = [point1[0], point2[0]]
                y_values = [point1[1], point2[1]]
                if self.tooFar[i]:
                    #line_artists[i] = self.ax.plot(x_values, y_values, ls='dotted', c=color[i], linewidth = .5)
                    line_artists[i] = plt.plot(x_values,
                                               y_values,
                                               ls='dotted',
                                               c=color[i],
                                               linewidth=.5)
                    pass
                elif not (self.collisions[i]):
                    line_artists[i] = plt.plot(x_values,
                                               y_values,
                                               ls="--",
                                               c=color[i],
                                               linewidth=1.5)
                else:
                    #line_artists[i] = self.ax.plot(x_values, y_values, ls='--', c=color[i])
                    line_artists[i] = plt.plot(x_values,
                                               y_values,
                                               ls='-.',
                                               c=color[i])

        instant_thorughput = 0
        for i in range(len(self.positions)):
            if self.choices[i] is not i:
                if not self.collisions[i]:
                    instant_thorughput += 1

        printing_names = [
            "Throughput", "Ave Throughput", "Collisions", "Out of Range",
            "Epoch", "Average Sink", "Sink Mov Avg"
        ]
        printing_values = [
            instant_thorughput, self.total_sent / (self.epochs + 1),
            sum(self.collisions),
            sum(self.tooFar), self.epochs, self.totalSunk / self.epochs,
            sum(self.moving_average_sink) / moving_average_length
        ]

        for i in range(len(self.positions)):
            printing_names.append("Q%d" % i)
            printing_values.append(self.U_values[i])
        for i in range(len(self.positions)):
            printing_names.append("Dest %d" % i)
            printing_values.append(self.choices[i])

        text_artists = [None for dummy in range(len(printing_names))]
        for i in range(len(printing_names)):
            text_artists[i] = plt.text(-.1,
                                       1 - (.025 * i),
                                       "%s = %.3f" %
                                       (printing_names[i], printing_values[i]),
                                       horizontalalignment='left',
                                       verticalalignment='center',
                                       transform=self.ax.transAxes)
        save_path = os.path.join(self.output_path,
                                 "epoch_{}.png".format(self.epochs))
        self.fig.savefig(save_path)

        for artist in plt.gca().lines:
            artist.remove()
        for artist in plt.gca().collections:
            artist.remove()
        for artist in line_artists:
            try:
                artist.remove()
            except:
                pass
        for line in self.ax.lines:
            try:
                line.remove()
            except:
                pass
        for artist in text_artists:
            if artist is not None:
                try:
                    artist.remove()
                except:
                    print(artist)
                    pass
        for artist in annotation_artists:
            if artist is not None:
                try:
                    artist.remove()
                except:
                    print(artist)
                    pass

        try:
            Artist.remove(scatter_artist)
        except:
            pass

        #plt.draw()
        #plt.clf()
        plt.close('all')