python - Matplotlib multiple lines on graph -


i've been having issue saving matplotlib graphs images. images saving differently shows when call .show() method on graph. example here: http://s1.postimg.org/lbyei5cfz/blue5.png

i'm not sure else do. i've spent past hours trying figure out what's causing it, can't figure out.

here code in it's entirety.

import matplotlib.pyplot plt import random turn = 1 #for x values class graph():     def __init__(self, name, color):         self.currentvalue = 5 #for y values         self.x = [turn]         self.y = [self.currentvalue]         self.name = name         self.color = color       def update(self):         if random.randint(0,1): #just show if graph's value goes or down             self.currentvalue += random.randint(0,10)             self.y.append(self.currentvalue)         else:             self.currentvalue -= random.randint(0,10)             self.y.append(self.currentvalue)         self.x.append(turn)      def plot(self):         lines = plt.plot(self.x,self.y)         plt.setp(lines, 'color',self.color)         plt.savefig(self.name + str(turn))         #plt.show() have different result plt.savefig(args)  graphs = [graph("red",'r'),graph("blue",'b'),graph("green",'g')] in range(5):     in graphs:         i.update() #changes x , y value         i.plot() #saves picture of graph     turn += 1 

sorry if stupid mistake i'm making, find peculiar how plt.show() , plt.savefig different.

thanks help.

as stated correctly david, plt.show() resets current figure. plt.savefig(), however, not, need reset explicitly. plt.clf() or plt.figure() 2 functions can dor you. insert call right after plt.savefig:

    plt.savefig(self.name + str(turn))     plt.clf() 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -