while d < end:
days_datetime.append(d)
d = d + datetime.timedelta(1)
- days_str = [d.strftime('%d') for d in days_datetime]
binary_pdf = io.BytesIO()
with PdfPages(binary_pdf) as pdf:
- a4 = (21./2.54, 29.7/2.54)
+ a4 = (29.7/2.54, 21./2.54)
title = 'Seepark Wassertemperatur {} {}'.format(MONTH_DE[begin.month-1], begin.year)
report_times = [datetime.time(10), datetime.time(15)]
- # table
- plt.figure(figsize=a4)
- columns = ['Datum']
- for t in report_times:
- columns.append('Wassertemperatur {} Uhr'.format(t.hour))
- cells = []
- for d in days_datetime:
- cell = ['{}, {}. {}'.format(DAY_OF_WEEK_DE[d.weekday()], d.day, MONTH_DE[d.month-1])]
- for t in report_times:
- report_datetime = datetime.datetime.combine(d.date(), t)
- closed_index = np.argmin(np.abs(x - report_datetime))
- if abs(x[closed_index] - report_datetime) > datetime.timedelta(hours=1):
- cell.append('N/A')
- else:
- value = y[closed_index]
- cell.append('{:.1f}° C'.format(value))
- cells.append(cell)
-
- ax = plt.gca()
- ax.table(cellText=cells, colLabels=columns,
- loc='upper left')
- ax.axis('off')
- plt.title(title)
- plt.subplots_adjust(left=0.1, right=0.9) # do not cut row labels
- pdf.savefig()
-
# graphic
plt.figure(figsize=a4)
plt.plot(x, y)
- plt.xticks(days_datetime, days_str, rotation='vertical')
- plt.xlabel('Tag')
- plt.ylabel('Temparatur in °C')
+ plt.xticks(days_datetime, [''] * len(days_datetime))
+ plt.ylabel('Temperatur in °C')
plt.axis(xmin=begin, xmax=end)
plt.grid()
plt.title(title)
+
+ # table
+ columns = []
+ for d in days_datetime:
+ columns.append('{}.'.format(d.day))
+ rows = []
+ for t in report_times:
+ rows.append('Wasser {:02d}:{:02d} °C'.format(t.hour, t.minute))
+ cells = []
+ for t in report_times:
+ columns.append('{}.'.format(d.day))
+ row_cells = []
+ for d in days_datetime:
+ report_datetime = datetime.datetime.combine(d.date(), t)
+ closest_index = np.argmin(np.abs(x - report_datetime))
+ if abs(x[closest_index] - report_datetime) > datetime.timedelta(hours=1):
+ cell = 'N/A'
+ else:
+ value = y[closest_index]
+ cell = '{:.1f}'.format(value)
+ row_cells.append(cell)
+ cells.append(row_cells)
+ table = plt.table(cellText=cells, colLabels=columns, rowLabels=rows, loc='bottom')
+ table.scale(xscale=1, yscale=2)
+ plt.title(title)
+ plt.subplots_adjust(left=0.15, right=0.97, bottom=0.3) # do not cut row labels
pdf.savefig()
pdf_info = pdf.infodict()