-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnc_plot.py
More file actions
37 lines (29 loc) · 754 Bytes
/
nc_plot.py
File metadata and controls
37 lines (29 loc) · 754 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
32
33
34
35
36
37
from netCDF4 import Dataset
import matplotlib.pyplot as plt
# Import netCDF file
ncfile1 = './data/data.nc'
data1 = Dataset(ncfile1)
var1 = data1.variables
ncfile2 = './data/reg.nc'
data2 = Dataset(ncfile2)
var2 = data2.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"Non linear regression", fontsize=16)
plt.xlabel(r'$x$', fontsize=14)
plt.ylabel(r'$y$', fontsize=14)
# Prepare Data to Plot
x1 = var1['x'][:]
y1 = var1['y'][:]
x2 = var2['x'][:]
y2 = var2['y'][:]
# Plot with Legends
plt.scatter(x1, y1, label='data')
plt.plot(x2, y2, label='regression', color='r')
# Other options
plt.legend(fontsize=12)
plt.grid()
plt.savefig("plot.png", dpi=300)