Skip to content
Snippets Groups Projects
Commit 1d1344ca authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Improved documentation of 'Plotting'.

parent 39ed488b
Branches
No related tags found
No related merge requests found
......@@ -3,16 +3,22 @@
@author: Laura C. Kühle
TODO: Give option to select plotting color
TODO: Add documentation to plot_boxplot()
TODO: Adjust documentation for plot_classification_accuracy()
TODO: Add documentation to plot_boxplot() -> Done
TODO: Adjust documentation for plot_classification_accuracy() -> Done
"""
from typing import Tuple
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import seaborn as sns
from numpy import ndarray
from sympy import Symbol
from Quadrature import Quadrature
from Initial_Condition import InitialCondition
matplotlib.use('Agg')
x = Symbol('x')
......@@ -20,16 +26,17 @@ z = Symbol('z')
sns.set()
def plot_solution_and_approx(grid, exact, approx, color_exact, color_approx):
""""Plots approximate and exact solution against each other.
def plot_solution_and_approx(grid: ndarray, exact: ndarray, approx: ndarray,
color_exact: str, color_approx: str) -> None:
"""Plots approximate and exact solution against each other.
Parameters
----------
grid : np.array
grid : ndarray
List of mesh evaluation points.
exact : np.array
exact : ndarray
Array containing exact evaluation of a function.
approx : np.array
approx : ndarray
Array containing approximate evaluation of a function.
color_exact : str
String describing color to plot exact solution.
......@@ -46,14 +53,14 @@ def plot_solution_and_approx(grid, exact, approx, color_exact, color_approx):
plt.title('Solution and Approximation')
def plot_semilog_error(grid, pointwise_error):
""""Plots semi-logarithmic error between approximate and exact solution.
def plot_semilog_error(grid: ndarray, pointwise_error: ndarray) -> None:
"""Plots semi-logarithmic error between approximate and exact solution.
Parameters
----------
grid : np.array
grid : ndarray
List of mesh evaluation points.
pointwise_error : np.array
pointwise_error : ndarray
Array containing pointwise difference between exact and approximate solution.
"""
......@@ -64,16 +71,16 @@ def plot_semilog_error(grid, pointwise_error):
plt.title('Semilog Error plotted at Evaluation points')
def plot_error(grid, exact, approx):
""""Plots error between approximate and exact solution.
def plot_error(grid: ndarray, exact: ndarray, approx: ndarray) -> None:
"""Plots error between approximate and exact solution.
Parameters
----------
grid : np.array
grid : ndarray
List of mesh evaluation points.
exact : np.array
exact : ndarray
Array containing exact evaluation of a function.
approx : np.array
approx : ndarray
Array containing approximate evaluation of a function.
"""
......@@ -84,8 +91,8 @@ def plot_error(grid, exact, approx):
plt.title('Errors')
def plot_shock_tube(num_grid_cells, troubled_cell_history, time_history):
""""Plots shock tube.
def plot_shock_tube(num_grid_cells: int, troubled_cell_history: list, time_history: list) -> None:
"""Plots shock tube.
Plots detected troubled cells over time to depict the evolution of shocks as shock tubes.
......@@ -95,7 +102,7 @@ def plot_shock_tube(num_grid_cells, troubled_cell_history, time_history):
Number of cells in the mesh. Usually exponential of 2.
troubled_cell_history : list
List of detected troubled cells for each time step.
time_history:
time_history: list
List of value of each time step.
"""
......@@ -110,21 +117,22 @@ def plot_shock_tube(num_grid_cells, troubled_cell_history, time_history):
plt.title('Shock Tubes')
def plot_details(fine_projection, fine_mesh, coarse_projection, basis, wavelet, multiwavelet_coeffs,
num_coarse_grid_cells, polynomial_degree):
""""Plots details of projection to coarser mesh..
def plot_details(fine_projection: ndarray, fine_mesh: ndarray, coarse_projection: ndarray,
basis: ndarray, wavelet: ndarray, multiwavelet_coeffs: ndarray,
num_coarse_grid_cells: int, polynomial_degree: int) -> None:
"""Plots details of projection to coarser mesh.
Parameters
----------
fine_projection, coarse_projection : np.array
fine_projection, coarse_projection : ndarray
Matrix of projection for each polynomial degree.
fine_mesh : np.array
fine_mesh : ndarray
List of evaluation points for fine mesh.
basis : np.array
basis : ndarray
Basis vector for calculation.
wavelet : np.array
wavelet : ndarray
Wavelet vector for calculation.
multiwavelet_coeffs : np.array
multiwavelet_coeffs : ndarray
Matrix of multiwavelet coefficients.
num_coarse_grid_cells : int
Number of cells in the coarse mesh (half the cells of the fine mesh).
......@@ -157,23 +165,24 @@ def plot_details(fine_projection, fine_mesh, coarse_projection, basis, wavelet,
plt.title('Wavelet Coefficients')
def calculate_approximate_solution(projection, points, polynomial_degree, basis):
def calculate_approximate_solution(projection: ndarray, points: ndarray, polynomial_degree: int,
basis: ndarray) -> ndarray:
"""Calculates approximate solution.
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
points : np.array
points : ndarray
List of evaluation points for mesh.
polynomial_degree : int
Polynomial degree.
basis : np.array
basis : ndarray
Basis vector for calculation.
Returns
-------
np.array
ndarray
Array containing approximate evaluation of a function.
"""
......@@ -190,13 +199,14 @@ def calculate_approximate_solution(projection, points, polynomial_degree, basis)
return np.reshape(np.array(approx), (1, len(approx) * num_points))
def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_len, quadrature,
init_cond):
def calculate_exact_solution(mesh: ndarray, cell_len: float, wave_speed: float, final_time: float,
interval_len: float, quadrature: Quadrature,
init_cond: InitialCondition) -> Tuple[ndarray, ndarray]:
"""Calculates exact solution.
Parameters
----------
mesh : array
mesh : ndarray
List of mesh valuation points.
cell_len : float
Length of a cell in mesh.
......@@ -213,7 +223,9 @@ def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_le
Returns
-------
np.array
grid: ndarray
Array containing evaluation grid for a function.
exact: ndarray
Array containing exact evaluation of a function.
"""
......@@ -239,21 +251,17 @@ def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_le
return grid, exact
def plot_classification_accuracy(evaluation_dict, colors):
def plot_classification_accuracy(evaluation_dict: dict, colors: dict) -> None:
"""Plots classification accuracy.
Plots the accuracy, precision, and recall in a bar plot.
Plots given evaluation measures in a bar plot for each model.
Parameters
----------
precision : float
Precision of classification.
recall : float
Recall of classification.
accuracy : float
Accuracy of classification.
xlabels : list
List of strings for x-axis labels.
evaluation_dict: dict
Dictionary containing classification evaluation data.
colors: dict
Dictionary containing plotting colors.
"""
model_names = evaluation_dict[list(colors.keys())[0]].keys()
......@@ -277,7 +285,19 @@ def plot_classification_accuracy(evaluation_dict, colors):
ax.legend(loc='upper right')
def plot_boxplot(evaluation_dict, colors):
def plot_boxplot(evaluation_dict: dict, colors: dict) -> None:
"""Plots classification accuracy.
Plots given evaluation measures in a boxplot for each model.
Parameters
----------
evaluation_dict: dict
Dictionary containing classification evaluation data.
colors: dict
Dictionary containing plotting colors.
"""
model_names = evaluation_dict[list(colors.keys())[0]].keys()
font_size = 16 - (len(max(model_names, key=len))//3)
fig = plt.figure('boxplot_accuracy')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment