plot_overtime_log.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#####################################################################################
# This file is part of NS2DDV. #
# #
# Copyright(C) 2011-2018 C. Calgaro (caterina.calgaro@math.univ-lille1.fr) #
# E. Creusé (emmanuel.creuse@math.univ-lille1.fr) #
# T. Goudon (thierry.goudon@inria.fr) #
# A. Mouton (alexandre.mouton@math.univ-lille1.fr) #
# #
# NS2DDV is free software: you can redistribute it and/or modify it under the terms #
# of the GNU General Public License as published by the Free Software Foundation, #
# either version 3 of the License, or (at your option) any later version. #
# #
# NS2DDV is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A #
# PARTICULAR PURPOSE. See the GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License along with #
# NS2DDV. If not, see <http://www.gnu.org/licenses/>. #
#####################################################################################
from readlog import *
def plot_data(datas, times, legends, ytext, ylim, outputfile):
if (not(len(times) == len(datas))):
print('Problem with data format in plot_data')
exit()
fs = 20
plt.rc('xtick',labelsize=fs)
plt.rc('ytick',labelsize=fs)
plt.rc('xtick.major', size=12)
plt.rc('ytick.major', size=12)
f = plt.figure(figsize=(19.2,12))
plt.xlabel('Time', fontsize=fs)
plt.ylabel(ytext, fontsize=fs)
for j in range(0,len(times)):
if (not(len(times[j]) == len(datas[j]))):
print('Problem with data format in plot_data')
exit()
if (ytext[0] == 'p'):
p = plt.plot(times[j][3:], datas[j][3:], label=legends[j], linewidth=3)
else:
p = plt.plot(times[j], datas[j], label=legends[j], linewidth=3)
lgd = plt.legend(fontsize=fs, ncol=1, loc='upper right', bbox_to_anchor=(1.37, 1))
axes = plt.gca()
if (not((ylim == 'default'))):
axes.set_ylim([ylim[0],ylim[1]])
plt.draw()
f.savefig(outputfile, bbox_extra_artists=(lgd,), bbox_inches='tight')
plt.close('all')
return axes.get_ylim()
def compare_plots(logfilesets, legendsets, field, ytext, outputfiles):
all_ylim = []
all_datas = []
all_times = []
j = 0
for logfileset in logfilesets:
# Read the log file set
if ((type(logfileset) == type(list())) and (type(legendsets) == type(list()))):
datas = []
times = []
for logfile in logfileset:
# Read the log file
[headers, diags] = read_logfile(logfile)
# Extract the data
diag = extract_data(headers, diags, field)
time = extract_data(headers, diags, 'TIME')
# Add it the data to be plotted
datas.append(diag)
times.append(time)
# Plot the data and get the y-limits of the obtained graph
ylim = plot_data(datas, times, legendsets[j], ytext, 'default', './.temp.png')
all_ylim.append(ylim)
# Store datas and times
all_datas.append(datas)
all_times.append(times)
j = j+1
else:
print('Problem in compare plot: first argument must be a list of lists')
exit()
new_ylim = [all_ylim[0][0], all_ylim[0][1]]
for ylim in all_ylim:
if (ylim[0] <= new_ylim[0]):
new_ylim[0] = ylim[0]
if (ylim[1] >= new_ylim[1]):
new_ylim[1] = ylim[1]
j = 0
for logfileset in logfilesets:
# Plot the data in the j-th log file set
ylim = plot_data(all_datas[j], all_times[j], legendsets[j], ytext, new_ylim, outputfiles[j])
j = j+1
os.system('rm ./.temp.png')
def compare_signals_sets(logfilesets, legendsets, fields, ytexts, xsignal, ysignal, xsignalalias, ysignalalias, outputprefixes):
if ((not(len(logfilesets) == len(legendsets))) and ((not(len(logfilesets) == len(outputprefixes))))):
print('Error: logfilesets, legendsets and outputprefixes arguments should be lists with same size')
exit()
for k in range(len(fields)):
fieldprefix = fields[k]
ytextprefix = ytexts[k]
for i in range(len(xsignal)):
x = xsignal[i]
xalias = xsignalalias[i]
for j in range(len(ysignal)):
y = ysignal[j]
yalias = ysignalalias[j]
field = fieldprefix + '(' + str(x)+','+str(y)+')'
ytext = ytextprefix + '(' + str(x)+','+str(y)+')'
outputfiles = []
for n in range(len(logfilesets)):
outputfile = outputprefixes[n]+'_'+ytextprefix+'_'+xalias+'_'+yalias+'.png'
outputfiles.append(outputfile)
compare_plots(logfilesets, legendsets, field, ytext, outputfiles)