-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexercise-1-sol.py
64 lines (50 loc) · 2.12 KB
/
exercise-1-sol.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
53
54
55
56
57
58
59
60
61
62
63
64
# -----------------------------------------------------------------------------
# Copyright (c) 2016, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
# Scientific visualization course
# G-Node 2016 summer school, University of Reading
# -----------------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
def gaussian(x, a, x0, sigma):
return a*np.exp(-(x-x0)**2/(2*sigma**2))
np.random.seed(123)
# Clean data
X = np.linspace(15, 21, 100)
Y = gaussian(X, 0.65, 17.6, 1.)
# Noisy dat
Xn = np.random.uniform(16, 20, 25)
Yn = gaussian(Xn, 0.65, 17.6, 1.) + 0.01 * np.random.normal(size=len(Xn))
plt.figure(figsize=(8,6), facecolor="w")
ax = plt.subplot(121)
plt.plot(X, 1000*Y, color='orange', linewidth=1.5, zorder=-10,
clip_on=False)
plt.scatter(Xn, 1000*Yn, s=50, marker=".", color="black")
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('axes', -0.1))
ax.spines['bottom'].set_color('0.5')
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('axes', -0.5))
ax.spines['left'].set_color('0.5')
plt.xlim(16,20)
plt.ylim(0,650)
plt.xticks([16,17.6,20],["16", "17.6 GHz", "20"])
plt.yticks([0, 325, 650], ["0", "", "650 mW"])
plt.tick_params(which='major', width=1.5, color="0.5")
ax.text(-0.5, 1.02, 'Output power',
verticalalignment='bottom', horizontalalignment='right',
transform=ax.transAxes, color='0.5', fontsize=12)
ax.text(18, 630, 'Measured',
transform=ax.transData, color='black', fontsize=12)
ax.text(18.5, 500, 'Calculated',
transform=ax.transData, color='orange', fontsize=12)
plt.tight_layout(pad=2.0)
[t.set_color('0.5') for t in ax.xaxis.get_ticklines()]
[t.set_color('0.5') for t in ax.xaxis.get_ticklabels()]
[t.set_color('0.5') for t in ax.yaxis.get_ticklines()]
[t.set_color('0.5') for t in ax.yaxis.get_ticklabels()]
plt.savefig("exercise-1-sol.png")
plt.show()