Skip to content
Snippets Groups Projects
Commit fe9e532c authored by Michael Reuscher's avatar Michael Reuscher
Browse files

New save for Plots

parent a21584d8
No related branches found
No related tags found
1 merge request!4Python driver and data analysis part
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()
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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment