diff --git a/src/main/python/plot.py b/src/main/python/plot.py index b72f48d..ff5578f 100644 --- a/src/main/python/plot.py +++ b/src/main/python/plot.py @@ -30,31 +30,39 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False): ls = CFG("plot_line_style") tup[FIGURE],tup[AXIS] = plt.subplots(1, 1) + # generate datapoints # + tupelsToIterate = [] for key in datapoints.keys(): - g = datapoints[key] - print(key) - #### Check if we are supposed to plot something #### - if not g.plot: - continue - #### GET AND CHECK TIMEFRAMES #### - x,y, = g.get_timeframe(tup[CALLBACK],date1,date2) - if not x or not y or len(x) <= 0 or len(y) <= 0: - print("Warning: Empty series of data '%s' (wrong start/end time?)"%g.name) - continue - else: - NO_SERIES = False - unix_x = [ el.timestamp() for el in x] - ymin,ymax = plot_graphutils.getlimits_y(y) + g = datapoints[key] + if not g.plot: + continue + x,y, = g.get_timeframe(tup[CALLBACK],date1,date2) + tupelsToIterate += [(x, y, g)] - #### GET LINE STYLES #### - legend_label = plot_graphutils.legend_box_contents(g.name,y) - tup[AXIS].plot(unix_x, y,ls=ls,lw=lw,marker="None", label=legend_label, color=g.color) + # check for negative values (legend padding) # + anyValueNegative = False + for x, y, g in tupelsToIterate: + anyValueNegative = anyValueNegative or min(y) < 0 + + # plot # + for x, y, g in tupelsToIterate: + if not x or not y or len(x) <= 0 or len(y) <= 0: + print("Warning: Empty series of data '%s' (wrong start/end time?)"%g.name) + continue + else: + NO_SERIES = False + unix_x = [ el.timestamp() for el in x] + ymin,ymax = plot_graphutils.getlimits_y(y) + + legend_label = plot_graphutils.legend_box_contents(g.name, y, anyValueNegative) + tup[AXIS].plot(unix_x, y, ls=ls, lw=lw, marker="None", + label=legend_label, color=g.color) legacy_x_save = x lagacy_y_save = y if NO_SERIES: - print("Error: no data, nothing to plot. cannot continue. exit.") - sys.exit(1) + print("Error: no data, nothing to plot. cannot continue. exit.") + sys.exit(1) ## GRID ## plot_graphutils.general_background_setup(tup, ymin, ymax, legacy_x_save) diff --git a/src/main/python/plot_graphutils.py b/src/main/python/plot_graphutils.py index 39c8b47..61d36a0 100644 --- a/src/main/python/plot_graphutils.py +++ b/src/main/python/plot_graphutils.py @@ -31,24 +31,32 @@ def getlimits_y(y): return (ymin, ymax) -def legend_box_contents(name, y): +def legend_box_contents(name, y, anyValueNegative): '''Return a string with the formate content of the legend/caption''' + padding = 4 + if anyValueNegative: + padding = 5 + + minFormatString = " min: {:" + str(padding) + ".1f}," + maxFormatString = " max: {:" + str(padding) + ".1f}," + avgFormatString = " Mittelwert: {:" + str(padding) + ".1f}," + # capping values at 99 makes formating easier# if CFG("cap_values_at_99"): y = [ min( [el, 99.9] ) for el in y ] # add minimum values if configured # if CFG("show_min"): - name += " min: {:4.1f},".format(min(y)) + name += minFormatString.format(min(y)) # add maximum values if configured # if CFG("show_max"): - name += " max: {:4.1f},".format(max(y)) + name += maxFormatString.format(max(y)) # show average if configured # if CFG("show_avg"): - name += " Mittelwert: {:4.1f},".format(sum(y)/float(len(y))) + name += avgFormatString.format(sum(y)/float(len(y))) return name.rstrip(",") def general_background_setup(tup,ymin,ymax,x):