Matlab Graph Matrix with Jet Spectrum Color, Label a Subset Examples
Plot a Subset of Data Matrix with Appropriate Legends
Sometimes we solve a model across many states, but we can only plot at a subset of states, or perhaps we plot at all states, but only show legends/labels for a subset.
In the example below, many lines are plotted, however, only a subset of lines are labeled in the legend.
ar_y = linspace(1,2,it_y_groups_n);
mat_y = rand([it_x_n, it_y_groups_n]);
mat_y = mat_y + sqrt(1:it_y_groups_n);
mat_y = mat_y + log(1:it_x_n)' + ar_y;
figure('PaperPosition', [0 0 7 4]);
set(chart(m),'Color',clr(m,:))
% invalid points separating lines
yline_borrbound = yline(3);
yline_borrbound.HandleVisibility = 'on';
yline_borrbound.LineStyle = ':';
yline_borrbound.Color = 'black';
yline_borrbound.LineWidth = 3;
title('Cash-on-Hand given w(k+b),k,z');
xlabel({'Index of Cash-on-Hand Discrete Point'...
'Each Segment is a w=k+b; within segment increasing k'...
'For each w and z, coh maximizing k is different'});
xlim([min(ar_x), max(ar_x)]);
legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/4) numel(chart)]);
legendCell = cellstr(num2str(ar_y', 'shock=%3.2f'));
legendCell{length(legendCell) + 1} = 'borrow-constraint';
chart(length(chart)+1) = yline_borrbound;
legend(chart([legend2plot length(legendCell)]), ...
legendCell([legend2plot length(legendCell)]), ...