Skip to content

Commit

Permalink
add profiles number on top of last subplot, pb with colobar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacques Grelet committed Apr 5, 2021
1 parent cb0bb3f commit 35a80d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PROF_ADCP = netcdf/OS_PIRATA-FR31_ADCP.nc -t ADCP -p -k DEPTH EWCT NSCT -c k- r-
SECT_ADCP = netcdf/OS_PIRATA-FR31_ADCP.nc -t ADCP -s --append 1N-10W_10S_10W -k DEPTH EWCT NSCT -l 5 28 --xaxis LATITUDE --yscale 0 250 250 2000 --xinterp 24 --yinterp 20 --clevels 30 --autoscale -150 150
PROF_XBT = netcdf/OS_PIRATA-FR31_XBT.nc -t XBT -p -k DEPTH TEMP DENS SVEL -c k- b- k- g- -g -l 1 5
SECT_XBT = netcdf/OS_PIRATA-FR31_XBT.nc -t XBT -s --append 10S-20S_10W -k DEPTH TEMP --xaxis LATITUDE -l 18 28 --yscale 0 250 250 900
SECT2_XBT = netcdf/OS_PIRATA-FR31_XBT.nc -t XBT -s --append 0-10W_0_23W -k DEPTH TEMP --xaxis LONGITUDE -l 39 61 --yscale 0 250 250 900 --xinterp 20 --yinterp 1s0 --clevels 30 -e 59
SECT2_XBT = netcdf/OS_PIRATA-FR31_XBT.nc -t XBT -s --append 0-10W_0_23W -k DEPTH TEMP --xaxis LONGITUDE -l 39 61 --yscale 0 250 250 900 --xinterp 20 --yinterp 10 --clevels 30 --autoscale 0 30 -e 59

.PHONY: clean-pyc clean-build clean lint test run build

Expand Down
32 changes: 20 additions & 12 deletions plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,24 +299,25 @@ def section(self, start, end, xaxis, yscale, exclude,
ymax = np.max(yscale)
# construct the vector index of the profiles list, without excluded value(s)
# this vector is use to extract the profiles from netcdf file
list_profiles = []
list_exclude = []
index_profiles = []
index_exclude = []
for i in exclude:
list_exclude.append(profiles.index(i))
index_exclude.append(profiles.index(i))
for i in range(start, end + 1):
try:
list_profiles.append(profiles.index(i))
index_profiles.append(profiles.index(i))
except:
print("invalid --list {}-{}, we use last profile = {}".format(start, end,
profiles[-1]))
i = i - 1
break
# remove the exclude list indice from profile list indice
# https://www.geeksforgeeks.org/python-indices-list-of-matching-element-from-other-list/?ref=rp
res = [i for i, val in enumerate(list_profiles) if val in list_exclude]
list_profiles = np.delete(list_profiles, res)
res = [i for i, val in enumerate(index_profiles) if val in index_exclude]
index_profiles = np.delete(index_profiles, res)
list_profiles = self.nc.variables['PROFILE'][index_profiles].tolist()

nbxi = len(list_profiles)
nbxi = len(index_profiles)
labelrotation = 15 if nbxi > 15 else 0
# if xinterp > end - start:
# xinterp = end - start
Expand All @@ -329,18 +330,18 @@ def section(self, start, end, xaxis, yscale, exclude,
labelrotation = 15
for k in range(1, len(self.keys)):
var = self.keys[k]
x = self.nc.variables[xaxis][list_profiles]
x = self.nc.variables[xaxis][index_profiles]
if xaxis == 'TIME':
for i in range(0, len(x)):
x[i] = dt2julian(julian2dt(x[i]))
y = self.nc.variables[yaxis][list_profiles, :]
y = self.nc.variables[yaxis][index_profiles, :]
# find index of the max value given by yscale
_, c = np.where(y >= ymax)
if c.size == 0:
sys.exit("invalid --yscale {}, max value must be <= {}".format(yscale.tolist(),
np.max(y)))
y = self.nc.variables[yaxis][list_profiles, :c[0]]
z = self.nc.variables[var][list_profiles, :c[0]]
y = self.nc.variables[yaxis][index_profiles, :c[0]]
z = self.nc.variables[var][index_profiles, :c[0]]
xi = np.linspace(x[0], x[-1], nbxi)
yi = np.arange(np.round(np.amin(y)),
np.ceil(np.amax(y))+ yinterp, yinterp)
Expand Down Expand Up @@ -419,10 +420,17 @@ def section(self, start, end, xaxis, yscale, exclude,
np.arange(np.round(np.min(x)), np.ceil(np.max(x))), minor=True)
ax.tick_params(axis='x', labelrotation=labelrotation)
ax.xaxis.set_major_formatter(x_formatter)
plt.colorbar(plt1, ax=ax)

# add a secondary axes on top with profiles number
ax2 = ax.twiny()
ax2.set_xlim(min(x),max(x))
ax2.set_xticks(x)
ax2.set_xticklabels(list_profiles, fontsize=6)

# Matplotlib 2 Subplots, 1 Colorbar
# https://stackoverflow.com/questions/13784201/matplotlib-2-subplots-1-colorbar
plt.colorbar(plt1, ax=fig.axes)
#plt.colorbar(plt1, ax=fig.axes)
ax.set_xlabel('{}'.format(self.nc.variables[xaxis].standard_name))
ylabel = '{} [{}]'.format(self.nc.variables[yaxis].standard_name,
self.nc.variables[yaxis].units)
Expand Down
14 changes: 8 additions & 6 deletions sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def section(ncfile, parameters, xaxis, start, end, yscale,
# find index of the max value given by yscale
r, c = np.where(y == pmax)
#y = y[:][0:columns[0]]
y = nc.variables[yaxis][start:end,:c[0]]
z = nc.variables[var][start:end,:c[0]]
y = nc.variables[yaxis][start:end, :c[0]]
z = nc.variables[var][start:end, :c[0]]
print(y.shape, z.shape)
xi = np.linspace(x[0], x[-1], nbxi)
yi = np.linspace(np.round(np.amin(y)), np.ceil(np.amax(y)), yinterp)
Expand Down Expand Up @@ -126,13 +126,15 @@ def section(ncfile, parameters, xaxis, start, end, yscale,
cs = ax.contour(xi, yi, zi, sublevels,
colors='black', linewidths=1.5)
ax.clabel(cs, inline=True, fmt='%3.1f', fontsize=8)
ax.set_xticks(np.arange(np.round(np.min(x)), np.ceil(np.max(x))),minor=True)
ax.set_xticks(np.arange(np.round(np.min(x)),
np.ceil(np.max(x))), minor=True)
ax.xaxis.set_major_formatter(x_formatter)
ax2 = ax.twiny()
ax2.spines["top"].set_position(("axes", 1.0))
print(x)
print(profiles[start:end])
#ax2.set_xlim(33,45)
#ax2.set_xticks(ax.get_xticks())
ax2.set_xlim(min(x),max(x))
ax2.set_xticks(x)
ax2.set_xticklabels(profiles[start:end])
# ax2.xaxis.set_major_formatter(profiles[start:end])

Expand All @@ -154,7 +156,7 @@ def section(ncfile, parameters, xaxis, start, end, yscale,
# section(ncfile, ['PRES', 'TEMP'], 'LATITUDE', 5, 28, [
# [0, 250], [250, 2000]], xinterp=20, yinterp=200, clevels=30, autoscale=[0, 30])
section(ncfile, ['PRES', 'TEMP'], 'TIME', 33, 49,
[0, 200], xinterp=16, yinterp=50, clevels=30, autoscale=[0, 30])
[0, 200], xinterp=16, yinterp=50, clevels=30, autoscale=[0, 30])
# section(ncfile, ['PRES', 'TEMP'], 'LATITUDE', 5, 28, [
# [0, 250], [250, 2000]], xinterp=20, yinterp=200, clevels=30, autoscale=[0, 30])
# # section(ncfile, ['PRES','PSAL'], 'LATITUDE', 5, 28, [[0,250], [250,2000]],clevels=15,autoscale=[34,37])
Expand Down

0 comments on commit 35a80d2

Please sign in to comment.