mirror of
https://github.com/FAUSheppy/ths-datenlogger
synced 2025-12-07 20:31:35 +01:00
pad negative numbers in legend box
This commit is contained in:
@@ -30,31 +30,39 @@ def __plot(tup, datapoints, path, date1=None, date2=None, forcePath=False):
|
|||||||
ls = CFG("plot_line_style")
|
ls = CFG("plot_line_style")
|
||||||
tup[FIGURE],tup[AXIS] = plt.subplots(1, 1)
|
tup[FIGURE],tup[AXIS] = plt.subplots(1, 1)
|
||||||
|
|
||||||
|
# generate datapoints #
|
||||||
|
tupelsToIterate = []
|
||||||
for key in datapoints.keys():
|
for key in datapoints.keys():
|
||||||
g = datapoints[key]
|
g = datapoints[key]
|
||||||
print(key)
|
if not g.plot:
|
||||||
#### Check if we are supposed to plot something ####
|
continue
|
||||||
if not g.plot:
|
x,y, = g.get_timeframe(tup[CALLBACK],date1,date2)
|
||||||
continue
|
tupelsToIterate += [(x, y, g)]
|
||||||
#### 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)
|
|
||||||
|
|
||||||
#### GET LINE STYLES ####
|
# check for negative values (legend padding) #
|
||||||
legend_label = plot_graphutils.legend_box_contents(g.name,y)
|
anyValueNegative = False
|
||||||
tup[AXIS].plot(unix_x, y,ls=ls,lw=lw,marker="None", label=legend_label, color=g.color)
|
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
|
legacy_x_save = x
|
||||||
lagacy_y_save = y
|
lagacy_y_save = y
|
||||||
|
|
||||||
if NO_SERIES:
|
if NO_SERIES:
|
||||||
print("Error: no data, nothing to plot. cannot continue. exit.")
|
print("Error: no data, nothing to plot. cannot continue. exit.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
## GRID ##
|
## GRID ##
|
||||||
plot_graphutils.general_background_setup(tup, ymin, ymax, legacy_x_save)
|
plot_graphutils.general_background_setup(tup, ymin, ymax, legacy_x_save)
|
||||||
|
|||||||
@@ -31,24 +31,32 @@ def getlimits_y(y):
|
|||||||
|
|
||||||
return (ymin, ymax)
|
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'''
|
'''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#
|
# capping values at 99 makes formating easier#
|
||||||
if CFG("cap_values_at_99"):
|
if CFG("cap_values_at_99"):
|
||||||
y = [ min( [el, 99.9] ) for el in y ]
|
y = [ min( [el, 99.9] ) for el in y ]
|
||||||
|
|
||||||
# add minimum values if configured #
|
# add minimum values if configured #
|
||||||
if CFG("show_min"):
|
if CFG("show_min"):
|
||||||
name += " min: {:4.1f},".format(min(y))
|
name += minFormatString.format(min(y))
|
||||||
|
|
||||||
# add maximum values if configured #
|
# add maximum values if configured #
|
||||||
if CFG("show_max"):
|
if CFG("show_max"):
|
||||||
name += " max: {:4.1f},".format(max(y))
|
name += maxFormatString.format(max(y))
|
||||||
|
|
||||||
# show average if configured #
|
# show average if configured #
|
||||||
if CFG("show_avg"):
|
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(",")
|
return name.rstrip(",")
|
||||||
|
|
||||||
def general_background_setup(tup,ymin,ymax,x):
|
def general_background_setup(tup,ymin,ymax,x):
|
||||||
|
|||||||
Reference in New Issue
Block a user