PLOTTSDIAGRAM Plot temperature-salinity diagram of glider data. Syntax: PLOTTSDIAGRAM(OPTIONS) PLOTTSDIAGRAM(OPT1, VAL1, ...) PLOTTSDIAGRAM(H, OPTIONS) PLOTTSDIAGRAM(H, OPT1, VAL1, ...) [HFIG, HAXS, HCTS, HLBS, HLNS] = PLOTTSDIAGRAM(...) Description: PLOTTSDIAGRAM(OPTIONS) and PLOTTSDIAGRAM(OPT1, VAL1, ...) generate a new figure with a line (marker) plot of temperature versus salinity samples of glider data on constant sigma-t level contours, according to options in key-value pairs OPT1, VAL1... or in struct OPTIONS with field names as option keys and field values as option values. The line plot is generated with function PLOT. Labeled contour levels are generated by functions CONTOUR and CLABELS from density measurements computed by SW_DENS0. Recognized options are: SDATA: salinity data (x-axis coordinate). Vector or matrix of salinity data. Default value: [] TDATA: temperature data (y-axis coordinate). Vector or matrix of temperature or potential temperature data. Default value: [] XLABEL: horizontal axis label data. Struct defining x label properties. The text of the label is in property 'String'. Default value: struct() YLABEL: vertical axis label data. Struct defining y label properties. The text of the label is in property 'String'. Default value: struct() TITLE: axes title data. Struct defining axes title properties. The text of the label is in property 'String'. 'String'. Default value: struct() AXSPROPS: extra axis properties. Struct of axis properties to set for the plot axes with function SET. Default value: struct() FIGPROPS: extra figure properties. Struct of figure properties to set for the figure with function SET. Default value: struct() PLOTTRANSECTVERTICALSECTION(H, ...) does not create a new figure, but plots to figure given by figure handle H. [HFIG, HAXS, HCTS, HLBS, HLNS] = PLOTTRANSECTVERTICALSECTION(...) returns handles for figure, axes, contour lines, contour labels and lineseries objects in HFIG, HAXS, HCTS, HLBS and HLNS, respectively. Notes: If input temperature is potential temperature instead of in situ temperature, base contour levels are potential density contour levels. Examples: [hfig, haxs, hcts, hlbs, hlns] = ... plotTSDiagram(gcf, ... 'SData', 37.5 + rand(30,5), 'TData', 10 + 15 * rand(30,5), ... 'Xlabel', struct('String', 'salinity'), ... 'Ylabel', struct('String', 'temperature'), ... 'title', struct('String', 'random TS plot on \sigma_t contours')) See also: SW_DENS0 Authors: Joan Pau Beltran <joanpau.beltran@socib.cat>
0001 function [hfig, haxs, hcts, hlbs, hlns] = plotTSDiagram(varargin) 0002 %PLOTTSDIAGRAM Plot temperature-salinity diagram of glider data. 0003 % 0004 % Syntax: 0005 % PLOTTSDIAGRAM(OPTIONS) 0006 % PLOTTSDIAGRAM(OPT1, VAL1, ...) 0007 % PLOTTSDIAGRAM(H, OPTIONS) 0008 % PLOTTSDIAGRAM(H, OPT1, VAL1, ...) 0009 % [HFIG, HAXS, HCTS, HLBS, HLNS] = PLOTTSDIAGRAM(...) 0010 % 0011 % Description: 0012 % PLOTTSDIAGRAM(OPTIONS) and PLOTTSDIAGRAM(OPT1, VAL1, ...) generate a new 0013 % figure with a line (marker) plot of temperature versus salinity samples of 0014 % glider data on constant sigma-t level contours, according to options in 0015 % key-value pairs OPT1, VAL1... or in struct OPTIONS with field names as 0016 % option keys and field values as option values. The line plot is generated 0017 % with function PLOT. Labeled contour levels are generated by functions 0018 % CONTOUR and CLABELS from density measurements computed by SW_DENS0. 0019 % Recognized options are: 0020 % SDATA: salinity data (x-axis coordinate). 0021 % Vector or matrix of salinity data. 0022 % Default value: [] 0023 % TDATA: temperature data (y-axis coordinate). 0024 % Vector or matrix of temperature or potential temperature data. 0025 % Default value: [] 0026 % XLABEL: horizontal axis label data. 0027 % Struct defining x label properties. 0028 % The text of the label is in property 'String'. 0029 % Default value: struct() 0030 % YLABEL: vertical axis label data. 0031 % Struct defining y label properties. 0032 % The text of the label is in property 'String'. 0033 % Default value: struct() 0034 % TITLE: axes title data. 0035 % Struct defining axes title properties. 0036 % The text of the label is in property 'String'. 0037 % 'String'. 0038 % Default value: struct() 0039 % AXSPROPS: extra axis properties. 0040 % Struct of axis properties to set for the plot axes with function SET. 0041 % Default value: struct() 0042 % FIGPROPS: extra figure properties. 0043 % Struct of figure properties to set for the figure with function SET. 0044 % Default value: struct() 0045 % 0046 % PLOTTRANSECTVERTICALSECTION(H, ...) does not create a new figure, 0047 % but plots to figure given by figure handle H. 0048 % 0049 % [HFIG, HAXS, HCTS, HLBS, HLNS] = PLOTTRANSECTVERTICALSECTION(...) returns 0050 % handles for figure, axes, contour lines, contour labels and lineseries 0051 % objects in HFIG, HAXS, HCTS, HLBS and HLNS, respectively. 0052 % 0053 % Notes: 0054 % If input temperature is potential temperature instead of in situ 0055 % temperature, base contour levels are potential density contour levels. 0056 % 0057 % Examples: 0058 % [hfig, haxs, hcts, hlbs, hlns] = ... 0059 % plotTSDiagram(gcf, ... 0060 % 'SData', 37.5 + rand(30,5), 'TData', 10 + 15 * rand(30,5), ... 0061 % 'Xlabel', struct('String', 'salinity'), ... 0062 % 'Ylabel', struct('String', 'temperature'), ... 0063 % 'title', struct('String', 'random TS plot on \sigma_t contours')) 0064 % 0065 % See also: 0066 % SW_DENS0 0067 % 0068 % Authors: 0069 % Joan Pau Beltran <joanpau.beltran@socib.cat> 0070 0071 % Copyright (C) 2013-2016 0072 % ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears 0073 % <http://www.socib.es> 0074 % 0075 % This program is free software: you can redistribute it and/or modify 0076 % it under the terms of the GNU General Public License as published by 0077 % the Free Software Foundation, either version 3 of the License, or 0078 % (at your option) any later version. 0079 % 0080 % This program is distributed in the hope that it will be useful, 0081 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0082 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0083 % GNU General Public License for more details. 0084 % 0085 % You should have received a copy of the GNU General Public License 0086 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0087 0088 % No argument number checking since any number of arguments is allowed. 0089 0090 %% Set plot options and default values. 0091 options = struct(); 0092 options.sdata = []; 0093 options.tdata = []; 0094 options.xlabel = struct(); 0095 options.ylabel = struct(); 0096 options.title = struct(); 0097 options.axsprops = struct(); 0098 options.figprops = struct(); 0099 0100 0101 %% Get optional figure handle and option arguments. 0102 if (nargin > 0) && isscalar(varargin{1}) && ishghandle(varargin{1}) 0103 args = varargin(2:end); 0104 hfig = figure(varargin{1}); 0105 else 0106 args = varargin; 0107 hfig = figure(); 0108 end 0109 0110 0111 %% Get options from extra arguments. 0112 % Parse option key-value pairs in any accepted call signature. 0113 if isscalar(args) && isstruct(args{1}) 0114 % Options passed as a single option struct argument: 0115 % field names are option keys and field values are option values. 0116 option_key_list = fieldnames(args{1}); 0117 option_val_list = struct2cell(args{1}); 0118 elseif mod(numel(args), 2) == 0 0119 % Options passed as key-value argument pairs. 0120 option_key_list = args(1:2:end); 0121 option_val_list = args(2:2:end); 0122 else 0123 error('glider_toolbox:plotTSDiagram:InvalidOptions', ... 0124 'Invalid optional arguments (neither key-value pairs nor struct).'); 0125 end 0126 % Overwrite default options with values given in extra arguments. 0127 for opt_idx = 1:numel(option_key_list) 0128 opt = lower(option_key_list{opt_idx}); 0129 val = option_val_list{opt_idx}; 0130 if isfield(options, opt) 0131 options.(opt) = val; 0132 else 0133 error('glider_toolbox:plotTSDiagram:InvalidOption', ... 0134 'Invalid option: %s.', opt); 0135 end 0136 end 0137 0138 0139 %% Set figure properties. 0140 set(hfig, options.figprops); 0141 0142 0143 %% Initialize all plot elements. 0144 haxs = gca(); 0145 hlns = plot(haxs, 0, 0); 0146 haxs_next = get(haxs, 'NextPlot'); 0147 set(haxs, 'NextPlot', 'add'); 0148 [~, hcts] = contour(haxs, [], [], []); 0149 hlbs = []; 0150 haxstit = title(haxs, []); 0151 haxsxlb = xlabel(haxs, []); 0152 haxsylb = ylabel(haxs, []); 0153 0154 0155 %% Set properties of plot elements. 0156 % valid_data = ~(isnan(options.sdata) | isnan(options.tdata)); 0157 % srange = quantile(options.sdata(valid_data), [0.0001 0.9999]) 0158 % trange = quantile(options.tdata(valid_data), [0.0001 0.9999]) 0159 valid_data = (10 < options.tdata) & (options.tdata < 40) ... 0160 & ( 2 < options.sdata) & (options.sdata < 40); 0161 srange = [min(options.sdata(valid_data)) max(options.sdata(valid_data))]; 0162 trange = [min(options.tdata(valid_data)) max(options.tdata(valid_data))]; 0163 [salt_grid, temp_grid] = meshgrid(linspace(srange(1), srange(2), 30), ... 0164 linspace(trange(1), trange(2), 30)); 0165 dns0_grid = sw_dens0(salt_grid, temp_grid) - 1000; 0166 set(hcts, 'XData', salt_grid, 'YData', temp_grid, 'ZData', dns0_grid); 0167 set(haxs, 'XLim', srange, 'YLim', trange); 0168 set(haxs, 'NextPlot', haxs_next); 0169 set(haxs, options.axsprops); 0170 set(haxstit, options.title); 0171 set(haxsxlb, options.xlabel); 0172 set(haxsylb, options.ylabel); 0173 set(hcts, 'LineColor', 0.125 * (get(haxs, 'XColor') + get(haxs, 'YColor'))); 0174 % Contour labels must be created here after setting axes properties. 0175 hlbs = clabel(get(hcts, 'ContourMatrix'), hcts, 'Rotation', 0); 0176 set(hlbs, 'FontSize', get(haxs, 'FontSize'), 'FontWeight', 'bold'); 0177 set(hlns, ... 0178 'XData', options.sdata, ... 0179 'YData', options.tdata, ... 0180 'LineStyle', 'none', 'LineWidth', 0.25 * get(hcts, 'LineWidth'), ... 0181 'Marker', 'o', 'MarkerSize', 4 * get(hcts, 'LineWidth'), ... 0182 'MarkerFaceColor', 0.375 * get(hcts, 'LineColor') + 0.625 * get(haxs, 'Color'), ... 0183 'MarkerEdgeColor', 0.625 * get(hcts, 'LineColor') + 0.375 * get(haxs, 'Color'), ... 0184 'Color', 0.625 * get(hcts, 'LineColor') + 0.375 * get(haxs, 'Color')); 0185 %{ 0186 %num_profiles = floor(max(options.cdata)); 0187 %hsct = plot(haxs, zeros(2, num_profiles), zeros(2, num_profiles)); 0188 for p = 1:num_profiles 0189 profile_data = (options.cdata == p); 0190 xdata = options.sdata(bsxfun(@and, valid_data, profile_data)); 0191 ydata = options.tdata(bsxfun(@and, valid_data, profile_data)); 0192 if sum(valid_data & profile_data)/sum(profile_data) < 0.5 0193 xdata = []; 0194 ydata = []; 0195 end 0196 set(hsct(p), ... 0197 'XData', xdata, 'YData', ydata, ... 0198 'Marker', 'o', 'MarkerSize', 4 * get(hcts, 'LineWidth'), ... 0199 'MarkerFaceColor', 0.25 * get(hcts, 'LineColor') + 0.75 * get(haxs, 'Color'), ... 0200 'MarkerEdgeColor', 0.75 * get(hcts, 'LineColor') + 0.25 * get(haxs, 'Color'), ... 0201 'LineStyle', '-', 'LineWidth', 0.25 * get(hcts, 'LineWidth'), ... 0202 'Color', 0.5 * get(hcts, 'LineColor') + 0.5 * get(haxs, 'Color')); 0203 end 0204 %} 0205 0206 end