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 numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns import seaborn as sns
from matplotlib.offsetbox import OffsetImage, AnnotationBbox from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import os import os
...@@ -8,9 +7,16 @@ sns.set_theme() ...@@ -8,9 +7,16 @@ sns.set_theme()
class SeabornPlotter: class SeabornPlotter:
def __init__(self, dataframe, name): def __init__(self, dataframe, name, data_path):
self.dataframe = dataframe self.dataframe = dataframe
self.name = name 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 @staticmethod
def _add_logo(logo_path, logo_size, logo_x, logo_y): def _add_logo(logo_path, logo_size, logo_x, logo_y):
...@@ -33,6 +39,7 @@ class SeabornPlotter: ...@@ -33,6 +39,7 @@ class SeabornPlotter:
def plot_histogram_various(self): def plot_histogram_various(self):
df = self.dataframe df = self.dataframe
folder = self._make_folder('Various_Events')
x = df['size'] x = df['size']
y = df['duration'] y = df['duration']
title = "Procedure: {}".format(self.name) title = "Procedure: {}".format(self.name)
...@@ -47,11 +54,13 @@ class SeabornPlotter: ...@@ -47,11 +54,13 @@ class SeabornPlotter:
plt.title(title) plt.title(title)
plt.grid(True) plt.grid(True)
plt.xticks(rotation=45) plt.xticks(rotation=45)
plt.savefig(title + ".svg", format='svg') plt.savefig(os.path.join(folder, f"{title}.svg"))
plt.show()
plt.close()
def plot_histogram_long(self): def plot_histogram_long(self):
df = self.dataframe df = self.dataframe
folder = self._make_folder('Long_Events')
x = df['seconds_since_start'] x = df['seconds_since_start']
y = df['duration'] y = df['duration']
title = "Long Procedure: {}".format(self.name) title = "Long Procedure: {}".format(self.name)
...@@ -65,12 +74,13 @@ class SeabornPlotter: ...@@ -65,12 +74,13 @@ class SeabornPlotter:
plt.title(title) plt.title(title)
plt.grid(True) plt.grid(True)
plt.xticks(rotation=45) plt.xticks(rotation=45)
plt.savefig(title + ".svg", format='svg') plt.savefig(os.path.join(folder, f"{title}.svg"))
plt.show()
plt.close()
def plot_statistics(self): def plot_statistics(self):
dataframes = self.dataframe dataframes = self.dataframe
folder = self._make_folder('Statistics')
for df_key, df in dataframes.items(): for df_key, df in dataframes.items():
operations = df['Group'].unique() operations = df['Group'].unique()
num_plots = len(operations) num_plots = len(operations)
...@@ -93,5 +103,6 @@ class SeabornPlotter: ...@@ -93,5 +103,6 @@ class SeabornPlotter:
ax.grid(True) ax.grid(True)
ax.set_ylim(bottom=global_min_speed, top=global_max_speed) # Set the Y-axis limits ax.set_ylim(bottom=global_min_speed, top=global_max_speed) # Set the Y-axis limits
plt.savefig(df_key + ".svg", format='svg') plt.savefig(os.path.join(folder, f"{df_key}.svg"))
plt.show()
plt.close()
import argparse import argparse
import os
import matplotlib import matplotlib
from .DataFrameCreator import DataFrameCreator from .DataFrameCreator import DataFrameCreator
from .SeabornPlotter import SeabornPlotter from .SeabornPlotter import SeabornPlotter
...@@ -13,13 +14,14 @@ def main(): ...@@ -13,13 +14,14 @@ def main():
parser.add_argument("-d", "--data_path", required=True, help="path to Data from Sim") parser.add_argument("-d", "--data_path", required=True, help="path to Data from Sim")
args = parser.parse_args() args = parser.parse_args()
data_path = args.data_path data_path = args.data_path
statistics_path = os.path.abspath(os.path.join(data_path, os.pardir))
# Import Data # Import Data
creator = DataFrameCreator(data_path) creator = DataFrameCreator(data_path)
v_dataframes, l_dataframes, s_dataframes = creator.create() v_dataframes, l_dataframes, s_dataframes = creator.create()
# Plot Statistics # Plot Statistics
s_plotter = SeabornPlotter(s_dataframes, 'statistics') s_plotter = SeabornPlotter(s_dataframes, 'statistics', statistics_path)
s_plotter.plot_statistics() s_plotter.plot_statistics()
# Plot Data # Plot Data
...@@ -27,7 +29,7 @@ def main(): ...@@ -27,7 +29,7 @@ def main():
if not v_dataframes[frame].empty: if not v_dataframes[frame].empty:
# Setup Plotter # Setup Plotter
frame_name = frame frame_name = frame
v_plotter = SeabornPlotter(v_dataframes[frame], frame_name) v_plotter = SeabornPlotter(v_dataframes[frame], frame_name, statistics_path)
# Plotter run # Plotter run
v_plotter.plot_histogram_various() v_plotter.plot_histogram_various()
...@@ -35,7 +37,7 @@ def main(): ...@@ -35,7 +37,7 @@ def main():
if not v_dataframes[frame].empty: if not v_dataframes[frame].empty:
# Setup Plotter # Setup Plotter
frame_name = frame frame_name = frame
l_plotter = SeabornPlotter(l_dataframes[frame], frame_name) l_plotter = SeabornPlotter(l_dataframes[frame], frame_name, statistics_path)
# Plotter run # Plotter run
l_plotter.plot_histogram_long() 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