diff options
| author | Robert Scheibe <rob.scheibe@gmail.com> | 2024-12-20 23:14:29 +0100 | 
|---|---|---|
| committer | Robert Scheibe <rob.scheibe@gmail.com> | 2024-12-20 23:14:29 +0100 | 
| commit | 44a4a65f8c7244244d9b9102193d682ba89d3048 (patch) | |
| tree | f0fd53a163c851c5d3144f875dc5fd85d14a67c9 | |
| parent | 3593215e7375389a6deea3802796b7476119e0fb (diff) | |
added script for plotted data
| -rwxr-xr-x | make_photo | 6 | ||||
| -rwxr-xr-x | plot.py | 77 | 
2 files changed, 80 insertions, 3 deletions
| @@ -1,10 +1,10 @@  #!/bin/bash  export LC_TIME=de_DE.utf-8  image=/mnt/ramdisk/$(date +'%H_%M').jpg -image_small=/mnt/ramdisk/$(date +'%H_%M')_thumb.jpg +#image_small=/mnt/ramdisk/$(date +'%H_%M')_thumb.jpg  rpicam-still -o $image  #add date string -convert $image -resize 1024x768 -gravity SouthEast -font DejaVu-Sans -pointsize 50 -stroke black -undercolor black -bordercolor white -border 10 -fill "rgba(255,255,255,0.5)"  -annotate +30+30  "$(date +\\'%Y-%m-%d %H:%M\')"  $image -convert $image -resize 200x150 $image_small +convert $image -resize 1024x768 -gravity SouthEast -font DejaVu-Sans -pointsize 50 -stroke black -undercolor black -fill "rgba(255,255,255,0.5)"  -annotate +30+30  "$(date +\\'%Y-%m-%d %H:%M\')"  $image +#convert $image -resize 200x150 $image_small @@ -0,0 +1,77 @@ +#!/usr/bin/python3 +import matplotlib.pyplot as plt +import numpy as np +from PIL import Image +import argparse + +# Funktion zum Erstellen des Temperaturdiagramms mit Achsenbeschriftungen und Transparenz +def create_temperature_plot_with_labels(output_filename): +    times = np.arange(0, 24, 0.5)  # Zeitpunkte (alle halbe Stunde) +    temperatures = 20 + 10 * np.sin(times / 24 * 2 * np.pi)  # Beispielhafte Sinuskurve für Temperaturen + +    # Grenzen für die y-Achse basierend auf den Temperaturdaten +    min_temp = np.floor(min(temperatures) / 5) * 5  # Abrunden auf das nächste Vielfache von 5 +    max_temp = np.ceil(max(temperatures) / 5) * 5   # Aufrunden auf das nächste Vielfache von 5 + +    # Temperaturdiagramm zeichnen +    plt.figure(figsize=(8, 2), dpi=100)  # Größe des Diagramms: 800x100 Pixel +    plt.plot(times, temperatures, color='yellow', linewidth=5, label='Temperatur') +    plt.ylim(min_temp, max_temp)  # Y-Achse auf den Bereich der Daten begrenzen +    plt.xlabel('Uhrzeit', color='white')  # X-Achsenbeschriftung +    plt.ylabel('Temperatur in °C',  color='white')  # Y-Achsenbeschriftung +    plt.xticks(np.arange(0, 25, 4), color='white')  # X-Achse in 4-Stunden-Schritten beschriften +    plt.yticks(np.arange(min_temp, max_temp + 1, 5), color='white')  # Y-Achse in Schritten von 5 beschriften +    plt.grid(color='gray', linestyle='--', linewidth=0.5, alpha=0.7) +    plt.tight_layout() + +    # Diagramm mit transparentem Hintergrund speichern +    plt.savefig(output_filename, transparent=True, bbox_inches='tight') +    plt.close() + +# Funktion zum Laden und Überprüfen des Basisbildes +def load_and_check_base_image(image_path): +    try: +        base_image = Image.open(image_path) +        if base_image.size != (1024, 768): +            raise ValueError("Das Basisbild muss eine Größe von 1024x768 Pixeln haben.") +        return base_image +    except Exception as e: +        print(f"Fehler beim Laden des Basisbildes: {e}") +        return None + +# Funktion zum Überlagern des Diagramms auf das Basisbild +def overlay_plot_on_image(base_image_path, plot_image_path, output_image_path): +    try: +        base_image = Image.open(base_image_path) +         +        plot_image = Image.open(plot_image_path) +         +        # Überlagern des Diagramms auf das Basisbild (mit Transparenz) +        base_image.paste(plot_image, (112, 0), plot_image)  # Zentrieren: (1024 - 800) / 2 = 112 + +        # Kombiniertes Bild speichern +        base_image.save(output_image_path) +        print(f"Kombiniertes Bild gespeichert als {output_image_path}") +    except Exception as e: +        print(f"Fehler beim Überlagern des Diagramms: {e}") + +# Hauptfunktion +def main(): +    parser = argparse.ArgumentParser(description="Overlay transparentes Temperaturdiagramm auf ein Bild.") +    parser.add_argument("image", help="Pfad zum Basisbild (1024x768 Pixel)") +    parser.add_argument("output", help="Pfad zum kombinierten Ausgabebild") +    args = parser.parse_args() + +    base_image_path = args.image +    output_image_path = args.output + +    # Temporäre Datei für das transparente Temperaturdiagramm +    plot_filename = "temperature_plot_with_labels.png" + +    # Schritte ausführen: Diagramm erstellen und überlagern +    create_temperature_plot_with_labels(plot_filename) +    overlay_plot_on_image(base_image_path, plot_filename, output_image_path) + +if __name__ == "__main__": +    main() + | 
