This repository has been archived on 2023-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
soft-an04/ReversalModel/make_plots.py

72 lines
1.8 KiB
Python
Raw Normal View History

2023-05-10 11:41:23 +00:00
#!/usr/bin/env python3
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib
2023-05-10 12:07:40 +00:00
import os
2023-05-10 11:41:23 +00:00
2023-05-10 12:07:40 +00:00
DIR: str = os.path.dirname(__file__)
2023-05-10 11:41:23 +00:00
2023-05-10 12:07:40 +00:00
matplotlib.use('pgf')
2023-05-10 11:41:23 +00:00
matplotlib.rcParams.update({
2023-05-10 12:07:40 +00:00
'pgf.texsystem': 'pdflatex',
2023-05-10 11:41:23 +00:00
'font.family': 'serif',
'text.usetex': True,
'pgf.rcfonts': False,
})
2023-05-10 12:07:40 +00:00
df = pd.read_csv(DIR + '/time.csv')
2023-05-10 11:41:23 +00:00
df['cpu'] = df['user'] + df['sys']
del df['real']
del df['user']
del df['sys']
df_cpu = df.loc[~df.cpu.isnull(), :]
del df_cpu['ltl']
df_cpu = df_cpu.melt(id_vars=['cpu'])
df_cpu['value'] = df_cpu['value'].astype(str)
df_timeout = df.loc[:, :].copy()
df_timeout['timeout'] = 0
df_timeout.loc[df_timeout['cpu'].isnull(), 'timeout'] = 1
del df_timeout['cpu']
def timeout_by(name: str) -> pd.DataFrame:
df_return = df_timeout.loc[:, [name, 'timeout']] \
.groupby(name) \
.mean() \
2023-05-10 11:41:23 +00:00
.reset_index()
df_return['timeout'] = df_return['timeout'] * 100
2023-05-10 11:41:23 +00:00
df_return[name] = df_return[name].astype(str)
return df_return
def plot_by(df_cpu: pd.DataFrame, name: str, color: any):
# Initialize the matplotlib figure
2023-05-10 12:07:40 +00:00
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))
2023-05-10 11:41:23 +00:00
sns.stripplot(ax=ax1, color=color, data=df_cpu.loc[df_cpu.variable == name],
2023-05-10 12:07:40 +00:00
x='cpu', y='value')
sns.barplot(ax=ax2, color=color, data=timeout_by(name), y=name, x='timeout',
2023-05-10 11:41:23 +00:00
width=0.75)
2023-05-10 12:07:40 +00:00
ax1.set(ylabel='Value of ' + name.upper(), xlim=[0, 300],
xlabel='CPU time (seconds)')
ax2.set(ylabel='Value of ' + name.upper(), xlim=[0, 100],
xlabel='Timeouts (%)')
2023-05-10 11:41:23 +00:00
sns.despine(left=True, bottom=True)
2023-05-10 12:07:40 +00:00
plt.savefig(DIR + '/../plots/' + name + '.pgf')
2023-05-10 11:41:23 +00:00
def main():
plot_by(df_cpu, 'n', 'teal')
plot_by(df_cpu, 'length', 'red')
plot_by(df_cpu, 'r', 'orange')
if __name__ == '__main__':
main()