From: peter <com...@ya...> - 2015-07-09 16:49:32
|
On 07/09/2015 06:40 PM, peter wrote: > hi, > > my code was working fine, but now i cant figure out what went wrong. > any ideas? > > the code is supposed to plot a timeseries which it does and overlay it > with another that is partially defined > the input file is contructed like this: > the first line is just for information purposes. > after that: > the first row is a growing number (the x value), the second is the > timeseries and the third is the partially defined second timeseries > > this is the code, after the code is a example input file. > the code is also accessible via this paste service: > https://dpaste.de/5ZrX it got a nice python code formatter. > ups, the last mail had a leading number from dpaste, this is the code without: def plotTimeSeriesAndSAX(inputfile_tmp, verbose=False): if verbose: print "plotTimeSeriesAndSAX()" print "\tinputfile:", inputfile_tmp print "\toutputfile: %s.png" % inputfile_tmp inputfile = open(inputfile_tmp, "r"); # this holds my timeseries x = [] y = [] # this holds my "pattern" pattern_x_values = [] pattern_y_values = [] # these are for temporary use only, hold the current pattern data tmp_x = [] tmp_y = [] # remove pattern/sax string, sax_string_with_Z from the datafile, only used as text in the plot first_line = inputfile.readline() pattern, sax, sax_string_with_Z = first_line.split() for line in inputfile.readlines(): data = line.split() x_data = data[0] y_data = data[1] #if there is a third line (pattern at this position) if len(data) == 3: y2_data = data[2] tmp_y.append(y2_data) tmp_x.append(x_data) else: # if the pattern ends, add it to pattern_x/y_value and clear the tmp list if len(tmp_x) != 0: pattern_x_values.append(tmp_x) pattern_y_values.append(tmp_y) tmp_x = [] tmp_y = [] x.append(x_data) y.append(y_data) #if pattern == "ccd": # print "pattern x_values:", pattern_x_values # print "pattern y_values:", pattern_y_values if verbose: print "\ttimeseries y value", y print "pattern x_values:", pattern_x_values print "pattern y_values:", pattern_y_values colors = ["red", "magenta", "mediumblue", "darkorchid", "grey"] #linestyle = ["-", "--"] # without this, the second plot contains the first and the second # the third plot contains: the first, second and third plot.clf() # plot all my patterns into the plot for s in range(0,len(pattern_x_values)): #if verbose: # print "\tpattern x value:", pattern_x_values[s] # print "\tpattern y value:", pattern_y_values[s] plot.plot(pattern_x_values[s], pattern_y_values[s], colors[1]) #plot.plot(x_all[0], y_all[0]) import matplotlib.patches as mpatches #red_patch = mpatches.Patch(color='red', label='The red data') from time import gmtime, strftime current_date = strftime("%Y-%m-%d %H:%M:%S", gmtime()) fig = plot.figure() fig.text(0, 0, 'bottom-left corner') fig.text(0, 1, current_date, ha='left', va='top') mytext = "pattern: %s sax: %s sax with Z: %s" % (pattern, sax, sax_string_with_Z) fig.text(1,1, mytext ) # add the original timeseries to the plot plot.plot(x,y, "forestgreen") #if pattern == "ccd": # plot.show() directory, filename = os.path.split(inputfile_tmp) plot.savefig(os.path.join(directory, "plots/%s.png" % filename))#, bbox_inches='tight') # remove the last figure from memory #plot.close() dee ccccccccccaacddeedcccccccdc ZZZZZZZZZZZZZZdeeZZZZZZZZZZ 1 -0.015920084 2 -0.044660769 3 -0.044660769 4 -0.092561907 5 0.012820599 6 -0.015920084 7 0.012820599 8 -0.054240996 9 0.031981054 10 0.031981054 11 -0.025500313 12 -0.044660769 13 0.012820599 14 -0.025500313 15 0.0032403709 16 -0.006339857 17 0.0032403709 18 -0.025500313 19 0.031981054 20 0.031981054 21 0.031981054 22 0.022400826 23 0.031981054 24 0.05114151 25 0.079882193 26 0.05114151 27 0.05114151 28 0.05114151 29 0.099042646 30 0.060721738 31 -0.015920084 32 -0.054240996 33 0.23316584 34 0.26190652 35 0.37686926 36 0.12778333 37 -0.044660769 38 -0.26500601 39 -0.41828965 40 -0.38954897 41 -0.26500601 42 -0.14046305 43 -0.073401452 44 -0.12130259 45 -0.082981679 46 -0.14046305 47 -0.054240996 48 -0.082981679 49 -0.015920084 50 -0.073401452 51 -0.015920084 52 0.10862288 53 1.1816084 54 -1.3379915 55 -4.6335899 56 -6.74124 57 -4.7772933 58 -3.4839626 59 -2.075669 60 -1.0984858 61 -0.37038851 62 -0.063821223 63 0.11820311 64 0.13736356 65 0.15652401 66 0.11820311 67 0.32896812 68 0.27148675 69 0.30022744 70 0.31938789 71 0.3577088 0.5449999999999999 72 0.40560994 0.5449999999999999 73 0.44393085 0.5449999999999999 74 0.49183198 0.5449999999999999 75 0.67385632 0.5449999999999999 76 0.79839928 0.84 77 0.9995841 0.84 78 1.1528677 0.84 79 1.4115338 0.84 80 1.5552373 0.84 81 1.7468418 0.84 82 1.7755825 0.84 83 1.7276813 0.84 84 1.4115338 0.84 85 1.0858061 0.84 86 0.65469586 87 0.43435063 88 0.21400538 89 0.14694379 90 0.089462421 91 0.070301966 92 0.031981054 93 0.05114151 94 0.070301966 95 0.13736356 96 0.079882193 97 0.12778333 98 0.15652401 99 0.16610425 100 0.13736356 101 0.13736356 102 0.089462421 103 0.2523263 104 0.21400538 105 0.22358561 106 0.1852647 107 0.19484493 108 0.1852647 109 0.16610425 110 0.13736356 111 0.15652401 112 0.14694379 113 0.16610425 114 0.099042646 115 0.12778333 116 0.13736356 117 0.089462421 118 0.079882193 119 0.089462421 120 0.041561282 121 0.041561282 122 0.079882193 123 0.11820311 124 0.099042646 125 0.089462421 126 0.05114151 127 0.17568447 128 0.30022744 129 0.32896812 130 0.42477039 131 0.17568447 132 0.022400826 133 -0.20752464 134 -0.24584556 135 -0.24584556 |