From fe9e532c60c35e4f2f67d921752b661c8f42d978 Mon Sep 17 00:00:00 2001 From: Michael Reuscher <michael.reuscher@desy.de> Date: Thu, 27 Jul 2023 09:55:35 +0200 Subject: [PATCH] New save for Plots --- visualizer/visualizer/SeabornPlotter.py | 29 +++++++++++++++++-------- visualizer/visualizer/main.py | 8 ++++--- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/visualizer/visualizer/SeabornPlotter.py b/visualizer/visualizer/SeabornPlotter.py index a09dea0..5247f01 100644 --- a/visualizer/visualizer/SeabornPlotter.py +++ b/visualizer/visualizer/SeabornPlotter.py @@ -1,6 +1,5 @@ import numpy as np import matplotlib.pyplot as plt -import pandas as pd import seaborn as sns from matplotlib.offsetbox import OffsetImage, AnnotationBbox import os @@ -8,9 +7,16 @@ sns.set_theme() class SeabornPlotter: - def __init__(self, dataframe, name): + def __init__(self, dataframe, name, data_path): self.dataframe = dataframe self.name = name + self.path = os.path.join(data_path, "Plots") + + def _make_folder(self, folder_name): + folder = os.path.join(self.path, folder_name) + if not os.path.exists(folder): + os.makedirs(folder) + return folder @staticmethod def _add_logo(logo_path, logo_size, logo_x, logo_y): @@ -33,6 +39,7 @@ class SeabornPlotter: def plot_histogram_various(self): df = self.dataframe + folder = self._make_folder('Various_Events') x = df['size'] y = df['duration'] title = "Procedure: {}".format(self.name) @@ -47,11 +54,13 @@ class SeabornPlotter: plt.title(title) plt.grid(True) plt.xticks(rotation=45) - plt.savefig(title + ".svg", format='svg') - plt.show() + plt.savefig(os.path.join(folder, f"{title}.svg")) + + plt.close() def plot_histogram_long(self): df = self.dataframe + folder = self._make_folder('Long_Events') x = df['seconds_since_start'] y = df['duration'] title = "Long Procedure: {}".format(self.name) @@ -65,12 +74,13 @@ class SeabornPlotter: plt.title(title) plt.grid(True) plt.xticks(rotation=45) - plt.savefig(title + ".svg", format='svg') - plt.show() + plt.savefig(os.path.join(folder, f"{title}.svg")) + + plt.close() def plot_statistics(self): dataframes = self.dataframe - + folder = self._make_folder('Statistics') for df_key, df in dataframes.items(): operations = df['Group'].unique() num_plots = len(operations) @@ -93,5 +103,6 @@ class SeabornPlotter: ax.grid(True) ax.set_ylim(bottom=global_min_speed, top=global_max_speed) # Set the Y-axis limits - plt.savefig(df_key + ".svg", format='svg') - plt.show() + plt.savefig(os.path.join(folder, f"{df_key}.svg")) + + plt.close() diff --git a/visualizer/visualizer/main.py b/visualizer/visualizer/main.py index d6622fc..117c573 100644 --- a/visualizer/visualizer/main.py +++ b/visualizer/visualizer/main.py @@ -1,4 +1,5 @@ import argparse +import os import matplotlib from .DataFrameCreator import DataFrameCreator from .SeabornPlotter import SeabornPlotter @@ -13,13 +14,14 @@ def main(): parser.add_argument("-d", "--data_path", required=True, help="path to Data from Sim") args = parser.parse_args() data_path = args.data_path + statistics_path = os.path.abspath(os.path.join(data_path, os.pardir)) # Import Data creator = DataFrameCreator(data_path) v_dataframes, l_dataframes, s_dataframes = creator.create() # Plot Statistics - s_plotter = SeabornPlotter(s_dataframes, 'statistics') + s_plotter = SeabornPlotter(s_dataframes, 'statistics', statistics_path) s_plotter.plot_statistics() # Plot Data @@ -27,7 +29,7 @@ def main(): if not v_dataframes[frame].empty: # Setup Plotter frame_name = frame - v_plotter = SeabornPlotter(v_dataframes[frame], frame_name) + v_plotter = SeabornPlotter(v_dataframes[frame], frame_name, statistics_path) # Plotter run v_plotter.plot_histogram_various() @@ -35,7 +37,7 @@ def main(): if not v_dataframes[frame].empty: # Setup Plotter frame_name = frame - l_plotter = SeabornPlotter(l_dataframes[frame], frame_name) + l_plotter = SeabornPlotter(l_dataframes[frame], frame_name, statistics_path) # Plotter run l_plotter.plot_histogram_long() -- GitLab