Newer
Older
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
from netCDF4 import Dataset
import numpy as np
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import os
# in batch mode, without display
#matplotlib.use('Agg')
file = 'OS_PIRATA-FR29_XBT.nc'
#ncpath = 'netcdf'
#path = 'plots'
ncpath = '.'
path = 'png'
ncfile = os.path.join(ncpath, file)
nc = Dataset(ncfile, mode='r')
TEMP = nc.variables['TEMP']
DEPTH = nc.variables['DEPTH']
PROFILE = nc.variables['PROFILE']
STATION = PROFILE.shape[0]
CM = nc.cycle_mesure
# move subplot outside loop prevent: RuntimeWarning: More than 20 figures have been opened.
fig, ax = plt.subplots()
for x in range(0,STATION):
temp = TEMP[x,:]
depth = DEPTH[x,:]
ax.plot(temp, depth)
ax.invert_yaxis()
ax.set(xlabel='{} ({})'.format(TEMP.long_name, TEMP.units), ylabel='{} ({})'.format(DEPTH.long_name,DEPTH.units),
title='{} - XBT Sippican profile n° {}'.format(CM, x+1))
ax.axis('auto')
ax.set_ylim(top=0)
ax.set_xlim(left=0, right=32)
ax.grid()
figname = '{}-{:03d}_XBT.png'.format(CM, x+1)
dest = os.path.join(path, figname)
fig.savefig(dest)
print('Printing: ', dest)
plt.show()
plt.cla()
#plt.close(fig)
print('Done.')