analistica/ex-6/plots/emd.py

45 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2020-05-13 01:16:45 +02:00
import numpy as np
import matplotlib.pyplot as plt
import sys
2020-05-13 01:16:45 +02:00
def plot(table, title='', log=False):
plt.figure(figsize=(5, 2))
plt.rcParams['font.size'] = 8
2020-05-13 01:16:45 +02:00
plt.suptitle(title)
plt.subplot(111)
2020-05-13 01:16:45 +02:00
if log:
plt.xscale('log')
2020-05-19 18:56:26 +02:00
plt.title('EMD' + ' '*10, loc='right')
2020-05-13 01:16:45 +02:00
plt.plot(table[0], table[1], color='#92182b')
plt.tick_params(axis='y', labelcolor='#92182b')
plt.ylabel('average', color='#92182b')
2020-05-19 18:56:26 +02:00
plt.ticklabel_format(style='sci', axis='y',
scilimits=(0, 0), useMathText=True)
2020-05-13 01:16:45 +02:00
twin = plt.twinx()
twin.plot(table[0], table[2], color='gray')
twin.tick_params(axis='y', labelcolor='gray')
twin.set_ylabel('standard deviation', color='gray')
2020-05-19 18:56:26 +02:00
twin.ticklabel_format(style='sci', axis='y',
scilimits=(0, 0), useMathText=True)
plt.tight_layout()
2020-05-13 01:16:45 +02:00
file = sys.argv[1] if len(sys.argv) > 1 else 'noiseless'
table = np.loadtxt('ex-6/plots/emd-' + file + '.txt')
if file == 'noiseless':
plot(table[:31].T, title=r'noise at $\sigma_N = 0.005$')
plot(table[31:51].T, title=r'noise at $\sigma_N = 0.005$')
plot(table[51:].T, title=r'noise at $\sigma_N = 0.01$')
else:
plot(table[:20].T, title=r'noise at $\sigma_N = 0.005$')
plot(table[20:40].T, title=r'noise at $\sigma_N = 0.005$')
plot(table[40:].T, title=r'noise at $\sigma_N = 0.01$')
plt.show()
2020-05-13 01:16:45 +02:00