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['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. # fig = plt.figure() #main fig, ax = plt.subplots(figsize=(width,height)) meshsize = [1/2, 1/4, 1/8, 1/16,1/32, 1/64, 1/128] # mesh-size CC_L2 = [6.894e-01,3.235e-02,8.298e-03 ,2.129e-03,5.370e-04, 1.340e-04 , 3.400e-05] #L2-Error CC_H1 = [6.580e+00,7.599e-01, 3.698e-01,1.839e-01, 9.181e-02, 4.589e-02, 2.294e-02] #H1-Error # --------------- Plot Lines + Scatter ----------------------- line_1 = ax.plot(meshsize, CC_L2, # data # color='forestgreen', # linecolor marker='D', # each marker will be rendered as a circle markersize=6, # marker size markerfacecolor='darkorange', # marker facecolor markeredgecolor='black', # marker edgecolor markeredgewidth=1, # marker edge width # linestyle='dashdot', # line style will be dash line linewidth=1.5, # line width zorder=3, label = r"$CC_{L_2}$") line_2 = ax.plot(meshsize, CC_H1, # data # color='orangered', # linecolor marker='o', # each marker will be rendered as a circle markersize=6, # marker size markerfacecolor='cornflowerblue', # marker facecolor markeredgecolor='black', # marker edgecolor markeredgewidth=1, # marker edge width # linestyle='--', # line style will be dash line linewidth=1.5, # line width zorder=3, alpha=0.8, # Change opacity label = r"$CC_{H_1}$") # --- 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"Some Computation $(\mathbb{R}\to \mathbb{R})$") # Plot - Title plt.xscale('log') # Use Logarithmic-Scale plt.yscale('log') ax.set_xlabel(r"Mesh size", labelpad=4) ax.set_ylabel(r"Error $||u-u_h ||_{L^2}$", 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('Plot_Template.pdf') # plt.show()