function varargout = techJoyPlot(data, years, techNames, offset, varargin) %TECHJOYPLOT Plot technology trends in a ridgeline representation % TECHJOYPLOT(DATA,YEARS,TECHNAMES,OFFSET) % DATA: m x n matrix where n is number of technologies, m is number of years % YEARS: vector of years corresponding to rows in DATA % TECHNAMES: cell array of technology names % OFFSET: vertical spacing between technologies %% Parse inputs p = inputParser; addRequired(p, 'data', @isnumeric); addRequired(p, 'years', @isnumeric); addRequired(p, 'techNames', @iscell); addRequired(p, 'offset', @isnumeric); % Default parameters addParameter(p, 'FaceColor', 'position', @(x) ischar(x) || isnumeric(x)); addParameter(p, 'FaceAlpha', 0.8, @isnumeric); addParameter(p, 'LineColor', 'k', @(x) ischar(x) || isnumeric(x)); addParameter(p, 'LineWidth', 0.5, @isnumeric); addParameter(p, 'Colormap', parula, @(x) ischar(x) || isnumeric(x)); parse(p, data, years, techNames, offset, varargin{:}); %% Data preparation years = years(:); [m, n] = size(data); % Normalize data for better visualization normData = data ./ max(data(:)) * offset * 0.8; % Calculate y positions for each technology ypos = (0:offset:(n-1)*offset)'; % Prepare patch coordinates X = repmat([years(1); years; years(end)], 1, n); Y = normData + repmat(ypos', m, 1); Y = [ypos'; Y; ypos']; %% Create plot ax = gca; hold on; % Create colored patches based on position if ischar(p.Results.FaceColor) && strcmp(p.Results.FaceColor, 'position') cmap = p.Results.Colormap; if ischar(cmap), cmap = feval(cmap, n); end faceColors = cmap(1:n,:); else faceColors = p.Results.FaceColor; end % Plot each technology for i = 1:n fill(X(:,i), Y(:,i), faceColors(i,:), ... 'FaceAlpha', p.Results.FaceAlpha, ... 'EdgeColor', p.Results.LineColor, ... 'LineWidth', p.Results.LineWidth); end % Add technology names as y-tick labels set(ax, 'YTick', ypos, 'YTickLabel', techNames); set(ax, 'TickLength', [0 0], 'YGrid', 'on'); % Format x-axis as years xlim([years(1)-1, years(end)+1]); datetick('x', 'yyyy', 'keeplimits'); hold off; % Return handles if requested if nargout > 0 varargout{1} = gcf; end end % Example data years = 2002:2024; techNames = {'PSO', 'SOA', 'GIM', 'WOA', 'GA'}; data = rand(11,5) .* repmat(linspace(1,5,11)',1,5); % Simulated trend data % Create plot figure; techJoyPlot(data, years, techNames, 1, ... 'FaceColor', 'position', ... 'Colormap', 'hot', ... 'FaceAlpha', 0.7); xlabel('Year'); title('Technology Trends Over Time');