-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_convergence_2d.py
executable file
·52 lines (47 loc) · 1.4 KB
/
plot_convergence_2d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
from __future__ import print_function
import numpy as np
import scipy as sp
from scipy import optimize
import matplotlib as mpl
from matplotlib import pyplot as plt
import sys
ORDERS = [2,4,6]
PLOT_NAME = "images/convergence_norm."
linewidth=3
markersize=12
fontsize=12
fontsize_labels=16
styles_data=['bo-','go-','ro-']
mpl.rcParams.update({'font.size': fontsize})
def f(dx,alpha,o):
return alpha + o*dx
if __name__ == "__main__":
if len(sys.argv) < 2:
print("{} FILENAME".format(sys.argv[0]))
quit()
filename = sys.argv[1]
data = np.loadtxt(filename)
nx = data[...,0]
ny = data[...,1]
errors = data[...,2:].transpose()
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
for i in range(errors.shape[0]):
dx = 2*np.pi/(nx[i]-1)
ax1.semilogy(nx,errors[i],styles_data[i],
lw=linewidth,ms=markersize,
label="order = {}".format(ORDERS[i]))
ax1.legend()
ax1.set_xlabel(r"nx",fontsize=fontsize_labels)
ax1.set_ylabel(r'$|error|_{2}$',
fontsize=fontsize_labels)
ax1.set_xticks(nx)
ax2.set_xlim(ax1.get_xlim())
ax2.set_xticks(nx)
ax2.set_xticklabels(map(int,ny))
ax2.set_xlabel(r"ny",fontsize=fontsize_labels)
for extension in ["png","pdf"]:
plt.savefig(PLOT_NAME+extension,
bbox_inches='tight')