-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnc_plot.py
More file actions
31 lines (25 loc) · 788 Bytes
/
nc_plot.py
File metadata and controls
31 lines (25 loc) · 788 Bytes
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
from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as np
# Import netCDF file
ncfile = './kde.nc'
data = Dataset(ncfile)
var = data.variables
# Use latex
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
# Prepare Plot
plt.figure(figsize=(10,6), dpi=300)
plt.title(r"KDE for Random walk", fontsize=16)
plt.xlabel(r'End points', fontsize=14)
plt.ylabel(r'Density', fontsize=14)
# Prepare Data to Plot
x = var['x'][:]
y = var['pdf'][:]
# Plot with Legends
plt.plot(x, y, 'r--', label=r'KDE ($\lambda=1$)', alpha=0.8)
plt.plot(x, np.exp(-x**2 / 20) / np.sqrt(20 * np.pi), 'b--', label=r'$\displaystyle w(x,\,10)=\frac{1}{\sqrt{20\pi}}e^{-\frac{x^2}{20}}$', alpha=0.5)
# Other options
plt.legend(fontsize=14)
plt.grid()
plt.savefig("plot.png", dpi=300)