def plot(self, x, y, markings='o-', c=None, color=None, linewidth=1, markersize=5, markeredgewidth=1, alpha=1, label=None): if c == None: count = {} # go through all existing colours, and count how often # they occur in the current list of used colours for i in range(len(self.colours)): count[str(self.colours[i])] = 0 for pi in range(len(self._plotlist)): if str(self._plotlist[pi]['colour']) not in count.keys(): count[str(self._plotlist[pi]['colour'])] = 0 count[str(self._plotlist[pi]['colour'])] += 1 # get the colour with the lowest count c = count.keys()[0] for col in count.keys(): if count[col] < count[c]: c = col # string to colour exec("c = %s" % c) else: c = check_colour(c) if len(c) == 1: c = (c, c, c) if len(c) == 3: c.append(255*alpha) # draw line for i in range(0, len(x)-1): spos = (x[i], y[i]) epos = x[i+1], y[i+1] if '-' in markings: pygame.draw.line(self.surf, c, spos, epos, linewidth) if 'o' in markings: pygame.draw.circle(self.surf, (0,0,0,255*alpha), spos, int(markersize/2), 0) pygame.draw.circle(self.surf, c, spos, int(markersize/2 - markeredgewidth), 0) if 'x' in markings: pygame.draw.line(self.surf, c, (spos[0]-markersize/2, spos[1]-markersize/2), (spos[0]+markersize/2, spos[1]+markersize/2), markeredgewidth) pygame.draw.line(self.surf, c, (spos[0]-markersize/2, spos[1]+markersize/2), (spos[0]+markersize/2, spos[1]-markersize/2), markeredgewidth) if 'o' in markings: pygame.draw.circle(self.surf, (0,0,0,255*alpha), epos, int(markersize/2), 0) pygame.draw.circle(self.surf, c, epos, int(markersize/2 - markeredgewidth), 0) if 'x' in markings: pygame.draw.line(self.surf, c, (epos[0]-markersize/2, epos[1]-markersize/2), (epos[0]+markersize/2, epos[1]+markersize/2), markeredgewidth) pygame.draw.line(self.surf, c, (epos[0]-markersize/2, epos[1]+markersize/2), (epos[0]+markersize/2, epos[1]-markersize/2), markeredgewidth) # append info on line to list plotinfo = { 'label':label, 'colour':c, 'linewidth':linewidth, 'markings':markings, 'markersize':markersize, 'markeredgewidth':markeredgewidth} self._plotlist.append(plotinfo)
def annotate(self, s, pos, c=None, color=None, fontsize=12, fontproperties=None): # set colour if c == None and color == None: colour = (0,0,0) elif c == None and color != None: colour = color elif c != None and color == None: colour = c else: colour = (0,0,0) # initialize font if fontproperties == None: font = pygame.font.Font(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Ubuntu-R.ttf'), fontsize) else: font = pygame.font.Font(fontproperties.fname, fontsize) text = font.render(s, True, check_colour(colour)) self.surf.blit(text, pos)