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

Added documentation to 'Plotting'.

parent a5264b2d
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,22 @@ sns.set()
def plot_solution_and_approx(grid, exact, approx, color_exact, color_approx):
""""Plots approximate and exact solution against each other.
Parameters
----------
grid : np.array
List of mesh evaluation points.
exact : np.array
Array containing exact evaluation of a function.
approx : np.array
Array containing approximate evaluation of a function.
color_exact : str
String describing color to plot exact solution.
color_approx : str
String describing color to plot approximate solution.
"""
print(color_exact, color_approx)
plt.figure('exact_and_approx')
plt.plot(grid[0], exact[0], color_exact)
......@@ -27,6 +43,16 @@ def plot_solution_and_approx(grid, exact, approx, color_exact, color_approx):
def plot_semilog_error(grid, pointwise_error):
""""Plots semi-logarithmic error between approximate and exact solution.
Parameters
----------
grid : np.array
List of mesh evaluation points.
pointwise_error : np.array
Array containing pointwise difference between exact and approximate solution.
"""
plt.figure('semilog_error')
plt.semilogy(grid[0], pointwise_error[0])
plt.xlabel('x')
......@@ -35,6 +61,18 @@ def plot_semilog_error(grid, pointwise_error):
def plot_error(grid, exact, approx):
""""Plots error between approximate and exact solution.
Parameters
----------
grid : np.array
List of mesh evaluation points.
exact : np.array
Array containing exact evaluation of a function.
approx : np.array
Array containing approximate evaluation of a function.
"""
plt.figure('error')
plt.plot(grid[0], exact[0]-approx[0])
plt.xlabel('X')
......@@ -43,6 +81,20 @@ def plot_error(grid, exact, approx):
def plot_shock_tube(num_grid_cells, troubled_cell_history, time_history):
""""Plots shock tube.
Plots detected troubled cells over time to depict the evolution of shocks as shock tubes.
Parameters
----------
num_grid_cells : int
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:
List of value of each time step.
"""
plt.figure('shock_tube')
for pos in range(len(time_history)):
current_cells = troubled_cell_history[pos]
......@@ -56,6 +108,27 @@ def plot_shock_tube(num_grid_cells, troubled_cell_history, time_history):
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..
Parameters
----------
fine_projection, coarse_projection : np.array
Matrix of projection for each polynomial degree.
fine_mesh : np.array
List of evaluation points for fine mesh.
basis : np.array
Basis vector for calculation.
wavelet : np.array
Wavelet vector for calculation.
multiwavelet_coeffs : np.array
Matrix of multiwavelet coefficients.
num_coarse_grid_cells : int
Number of cells in the coarse mesh (half the cells of the fine mesh).
Usually exponential of 2.
polynomial_degree : int
Polynomial degree.
"""
averaged_projection = [[coarse_projection[degree][cell] * basis[degree].subs(x, value)
for cell in range(num_coarse_grid_cells)
for value in [-0.5, 0.5]]
......@@ -81,6 +154,25 @@ def plot_details(fine_projection, fine_mesh, coarse_projection, basis, wavelet,
def calculate_approximate_solution(projection, points, polynomial_degree, basis):
""""Calculates approximate solution.
Parameters
----------
projection : np.array
Matrix of projection for each polynomial degree.
points : np.array
List of evaluation points for mesh.
polynomial_degree : int
Polynomial degree.
basis : np.array
Basis vector for calculation.
Returns
-------
np.array
Array containing approximate evaluation of a function.
"""
num_points = len(points)
basis_matrix = [[basis[degree].subs(x, points[point]) for point in range(num_points)]
......@@ -96,6 +188,31 @@ def calculate_approximate_solution(projection, points, polynomial_degree, basis)
def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_len, quadrature,
init_cond):
""""Calculates exact solution.
Parameters
----------
mesh : array
List of mesh valuation points.
cell_len : float
Length of a cell in mesh.
wave_speed : float
Speed of wave in rightward direction.
final_time : float
Final time for which approximation is calculated.
interval_len : float
Length of the interval between left and right boundary.
quadrature : Quadrature object
Quadrature for evaluation.
init_cond : InitialCondition object
Initial condition for evaluation.
Returns
-------
np.array
Array containing exact evaluation of a function.
"""
grid = []
exact = []
num_periods = np.floor(wave_speed * final_time / interval_len)
......@@ -119,6 +236,22 @@ def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_le
def plot_classification_accuracy(precision, recall, accuracy, xlabels):
"""Plots classification accuracy.
Plots the accuracy, precision, and recall in a bar plot.
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.
"""
precision = [precision]
recall = [recall]
accuracy = [accuracy]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment