-
Klaus Böhnlein authoredKlaus Böhnlein authored
WoodBilayer_ExperimentComparisonError.py 9.89 KiB
import numpy as np
import matplotlib.pyplot as plt
import math
import os
import subprocess
import fileinput
import re
import sys
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.cm as cm
import matplotlib.ticker as ticker
from matplotlib.ticker import MultipleLocator,FormatStrFormatter,MaxNLocator
import seaborn as sns
import matplotlib.colors as mcolors
# ----------------------------------------------------
# --- Define Plot style:
# plt.style.use("seaborn-white")
# plt.style.use("seaborn-pastel")
# plt.style.use("seaborn-colorblind")
plt.style.use("seaborn")
mpl.rcParams['text.usetex'] = True
mpl.rcParams["font.family"] = "serif"
mpl.rcParams["font.size"] = "14"
mpl.rcParams['xtick.bottom'] = True
mpl.rcParams['xtick.major.size'] = 3
mpl.rcParams['xtick.minor.size'] = 1.5
mpl.rcParams['xtick.major.width'] = 0.75
mpl.rcParams['ytick.left'] = True
mpl.rcParams['ytick.major.size'] = 3
mpl.rcParams['ytick.minor.size'] = 1.5
mpl.rcParams['ytick.major.width'] = 0.75
#Adjust grid:
mpl.rcParams.update({"axes.grid" : True}) # Add grid
mpl.rcParams['axes.labelpad'] = 3
mpl.rcParams['grid.linewidth'] = 0.25
mpl.rcParams['grid.alpha'] = 0.9 # 0.75
mpl.rcParams['grid.linestyle'] = '-'
mpl.rcParams['grid.color'] = 'gray'#'black'
mpl.rcParams['text.latex.preamble'] = r'\usepackage{amsfonts}' # Makes Use of \mathbb possible.
# ----------------------------------------------------------------------------------------
width = 5.79
height = width / 1.618 # The golden ratio.
#TODO read values from .txt output files....
dataset_numbers = [0, 1, 2, 3, 4 ,5]
for dataset_number in dataset_numbers:
# fig = plt.figure() #main
# fig, (ax1, ax2) = plt.subplots(1,2, figsize=(width,height))
# fig, (ax1, ax2) = plt.subplots(1,2)
fig, ax = plt.subplots(figsize=(width,height))
# fig = plt.figure(figsize=(10, 4))
# subfigs = fig.subfigures(1, 2, wspace=0.07)
# ax1 = subfigs[0]
# ax2 = subfigs[1]
dataset = [
[ # Dataset Ratio r = 0.12
[14.70179844, 13.6246 , 12.42994508, 11.69773413,11.14159987, 9.500670278, 9.005046347] , # input (moisture-content in %)
[1.29323308, 1.83458647 , 2.40601504 , 2.76691729 , 3.03759398, 3.81954887 , 4.03007519], # curvature kappa from Simulation
[1.140351217, 1.691038688, 2.243918105, 2.595732726, 2.945361006,4.001528043, 4.312080261] # curvature kappa from Experiment
],
[ # Dataset Ratio r = 0.17
[14.75453569,13.71227639,12.54975012,11.83455959,11.29089521,9.620608917,9.101671742], # input (moisture-content in %)
[1.26315789, 1.77443609, 2.34586466, 2.70676692, 2.97744361, 3.78947368,4.03007519], # curvature kappa from Simulation
[1.02915975,1.573720805,2.407706364,2.790518802,3.173814476,4.187433094,4.511739072] # curvature kappa from Experiment
],
[ # Dataset Ratio r = 0.22
[14.72680026, 13.64338887, 12.41305478, 11.66482931, 11.09781471, 9.435795985, 8.959564147], # input (moisture-content in %)
[1.20401338 , 1.72575251 , 2.28762542 , 2.64882943 , 2.92976589 , 3.73244147 , 3.93311037 ], # curvature kappa from Simulation
[1.058078122, 1.544624544, 2.317033799, 2.686043143, 2.967694189, 3.913528418, 4.262750825] # curvature kappa from Experiment
],
[ # Dataset Ratio r = 0.34
[14.98380876,13.97154915,12.77309253,12.00959929,11.42001731,9.561447179,8.964704969], # input (moisture-content in %)
[0.87218045, 1.26315789, 1.7443609, 2.07518797, 2.28571429, 3.03759398, 3.27819549], # curvature kappa from Simulation
[0.789078472,1.1299263,1.738136936,2.159520896,2.370047499,3.088299431,3.18097558] # curvature kappa from Experiment
],
[ # Dataset Ratio r = 0.43
[15.11316339,14.17997082,13.05739844,12.32309209,11.74608518,9.812372466,9.10519385 ], # input (moisture-content in %)
[0.63157895, 0.93233083, 1.29323308, 1.53383459, 1.71428571, 2.34586466,2.55639098], # curvature kappa from Simulation
[0.577989364,0.829007544,1.094211707,1.325332511,1.400455154,1.832325697,2.047483977] # curvature kappa from Experiment
],
[ # Dataset Ratio r = 0.49
[15.30614414,14.49463867,13.46629742,12.78388234,12.23057715,10.21852839,9.341730605], # input (moisture-content in %)
[0.60150376, 0.87218045, 1.23308271, 1.5037594 , 1.71428571, 2.46616541,2.79699248], # curvature kappa from Simulation
[0.357615902,0.376287785,0.851008627,0.904475291,1.039744708,1.346405241,1.566568558] # curvature kappa from Experiment
]
]
# input = [14.72680026, 13.64338887, 12.41305478, 11.66482931, 11.09781471, 9.435795985, 8.959564147] #moisture-content (in %)
# kappa_sim = [1.20401338 , 1.72575251, 2.28762542 , 2.64882943 , 2.92976589 , 3.73244147 , 3.93311037 ] #kappa from Simulation
# kappa_exp = [1.058078122,1.544624544, 2.317033799, 2.686043143, 2.967694189, 3.913528418, 4.262750825] #kappa from Experiment
# compute difference:
# relative_error = (np.array(kappa_sim) - np.array(kappa_exp)) / np.array(kappa_exp)
# print('relative_error:', relative_error)
relative_error = (np.array(dataset[dataset_number][1]) - np.array(dataset[dataset_number][2])) / np.array(dataset[dataset_number][2])
print('relative_error:', relative_error)
# --------------- Plot Lines + Scatter -----------------------
# line_1 = ax.plot(np.array(dataset[dataset_number][0]), np.array(dataset[dataset_number][1]), # data
# # color='forestgreen', # linecolor
# marker='D', # each marker will be rendered as a circle
# markersize=5, # marker size
# # markerfacecolor='darkorange', # marker facecolor
# markeredgecolor='black', # marker edgecolor
# markeredgewidth=0.75, # marker edge width
# # linestyle='dashdot', # line style will be dash line
# linewidth=1.5, # line width
# zorder=3,
# label = r"$\kappa_{sim}$")
# line_2 = ax.plot(np.array(dataset[dataset_number][0]), np.array(dataset[dataset_number][2]), # data
# # color='orangered', # linecolor
# marker='o', # each marker will be rendered as a circle
# markersize=5, # marker size
# # markerfacecolor='cornflowerblue', # marker facecolor
# markeredgecolor='black', # marker edgecolor
# markeredgewidth=0.75, # marker edge width
# # linestyle='--', # line style will be dash line
# linewidth=1.5, # line width
# zorder=3,
# alpha=0.8, # Change opacity
# label = r"$\kappa_{exp}$")
line_3 = ax.plot(np.array(dataset[dataset_number][0]), relative_error, # data
# color='orangered', # linecolor
marker='o', # each marker will be rendered as a circle
markersize=5, # marker size
# markerfacecolor='cornflowerblue', # marker facecolor
markeredgecolor='black', # marker edgecolor
markeredgewidth=0.75, # marker edge width
# linestyle='--', # line style will be dash line
linewidth=1.5, # line width
zorder=3,
alpha=0.8, # Change opacity
label = r"relative error")
# --- Plot order line
# x = np.linspace(0.01,1/2,100)
# y = CC_L2[0]*x**2
# OrderLine = ax.plot(x,y,linestyle='--', label=r"$\mathcal{O}(h)$")
# Fix_value = 7.674124
# l3 = plt.axhline(y = Fix_value, color = 'black', linewidth=0.75, linestyle = 'dashed')
# --------------- Set Axes -----------------------
# ax.set_title(r"ratio $r = 0.22$") # Plot - Title
# Plot - Title
match dataset_number:
case 0:
ax.set_title(r"ratio $r = 0.12$")
case 1:
ax.set_title(r"ratio $r = 0.17$")
case 2:
ax.set_title(r"ratio $r = 0.22$")
case 3:
ax.set_title(r"ratio $r = 0.34$")
case 4:
ax.set_title(r"ratio $r = 0.43$")
case 5:
ax.set_title(r"ratio $r = 0.49$")
# plt.xscale('log') # Use Logarithmic-Scale
# plt.yscale('log')
ax.set_xlabel(r"Wood moisture content $\omega (\%)$", labelpad=4)
ax.set_ylabel(r"relative error $\frac{\kappa_{sim}-\kappa_{exp}}{\kappa_{\exp}}$", labelpad=4)
plt.tight_layout()
# # --- Set Line labels
# line_labels = [r"$CC_{L_2}$",r"$CC_{H_1}$", r"$\mathcal{O}(h)$"]
# --- Set Legend
legend = ax.legend()
# legend = fig.legend([line_1 , line_2, OrderLine],
# labels = line_labels,
# bbox_to_anchor=[0.97, 0.50],
# # bbox_to_anchor=[0.97, 0.53],
# # loc='center',
# ncol=1, # Number of columns used for legend
# # borderaxespad=0.15, # Small spacing around legend box
# frameon=True,
# prop={'size': 10})
frame = legend.get_frame()
frame.set_edgecolor('black')
# --- Adjust left/right spacing:
# plt.subplots_adjust(right=0.81)
# plt.subplots_adjust(left=0.11)
# ---------- Output Figure as pdf:
fig.set_size_inches(width, height)
fig.savefig('WoodBilayer_expComparison_' + str(dataset_number) + 'relError.pdf')
# plt.show()