more and more
This commit is contained in:
@@ -19,66 +19,85 @@ end
|
||||
ax = gca;
|
||||
|
||||
% ---------------------------------------------------------
|
||||
% Extract *only* real data lines from ax.Children
|
||||
% Extract real data objects from ax.Children
|
||||
% ---------------------------------------------------------
|
||||
children = ax.Children;
|
||||
isLine = arrayfun(@(h) isa(h,'matlab.graphics.chart.primitive.Line'), children);
|
||||
lines = children(isLine);
|
||||
isScatter = arrayfun(@(h) isa(h,'matlab.graphics.chart.primitive.Scatter'), children);
|
||||
|
||||
% Remove helper lines (e.g. yline, fit overlays)
|
||||
lines = lines(~strcmp({lines.Tag},'ConstantLine'));
|
||||
isConstantLine = arrayfun(@(h) isprop(h,'Tag') && strcmp(h.Tag,'ConstantLine'), children);
|
||||
|
||||
n = numel(lines);
|
||||
if n == 0
|
||||
return
|
||||
end
|
||||
dataObjects = children((isLine | isScatter) & ~isConstantLine);
|
||||
n = numel(dataObjects);
|
||||
|
||||
% ---------------------------------------------------------
|
||||
% Fixed color palette (deterministic across figures)
|
||||
% ---------------------------------------------------------
|
||||
try
|
||||
cmap = linspecer(n);
|
||||
catch
|
||||
cmap = lines(n).Color; %#ok<NASGU>
|
||||
cmap = linespecer_fallback(n);
|
||||
if n > 0
|
||||
try
|
||||
cmap = linspecer(n);
|
||||
catch
|
||||
cmap = linespecer_fallback(n);
|
||||
end
|
||||
end
|
||||
|
||||
markers = {'o','s','o','o','^','v','d','>'};
|
||||
lw = 0.8;
|
||||
ms = 4;
|
||||
ms = 2;
|
||||
|
||||
% ---------------------------------------------------------
|
||||
% Apply line + marker styling
|
||||
% Apply line/scatter + marker styling
|
||||
% ---------------------------------------------------------
|
||||
for i = 1:n
|
||||
ln = lines(n-i+1); % preserve plotting order
|
||||
ln.LineWidth = lw;
|
||||
|
||||
if options.setcolors
|
||||
ln.Color = cmap(i,:);
|
||||
end
|
||||
dataObj = dataObjects(n-i+1); % preserve plotting order
|
||||
|
||||
if isa(dataObj,'matlab.graphics.chart.primitive.Line')
|
||||
dataObj.LineWidth = lw;
|
||||
|
||||
if options.setmarkers
|
||||
if strcmp(ln.Marker,'none')
|
||||
ln.Marker = markers{mod(i-1,numel(markers))+1};
|
||||
end
|
||||
ln.MarkerSize = ms;
|
||||
if options.setcolors
|
||||
ln.MarkerEdgeColor = cmap(i,:);
|
||||
dataObj.Color = cmap(i,:);
|
||||
end
|
||||
|
||||
if options.setmarkers
|
||||
if strcmp(dataObj.Marker,'none')
|
||||
dataObj.Marker = markers{mod(i-1,numel(markers))+1};
|
||||
end
|
||||
dataObj.MarkerSize = ms;
|
||||
if options.setcolors
|
||||
dataObj.MarkerEdgeColor = cmap(i,:);
|
||||
end
|
||||
dataObj.MarkerFaceColor = [1 1 1];
|
||||
end
|
||||
elseif isa(dataObj,'matlab.graphics.chart.primitive.Scatter')
|
||||
if options.setcolors
|
||||
dataObj.CData = cmap(i,:);
|
||||
dataObj.MarkerEdgeColor = cmap(i,:);
|
||||
markerFaceColor = dataObj.MarkerFaceColor;
|
||||
hasNoFace = ischar(markerFaceColor) && strcmp(markerFaceColor,'none');
|
||||
if ~hasNoFace
|
||||
dataObj.MarkerFaceColor = cmap(i,:);
|
||||
end
|
||||
end
|
||||
|
||||
if options.setmarkers
|
||||
if strcmp(dataObj.Marker,'none')
|
||||
dataObj.Marker = markers{mod(i-1,numel(markers))+1};
|
||||
end
|
||||
dataObj.SizeData = ms^2;
|
||||
end
|
||||
ln.MarkerFaceColor = [1 1 1];
|
||||
end
|
||||
end
|
||||
|
||||
% ---------------------------------------------------------
|
||||
% Optional smoothing / fitting overlay
|
||||
% ---------------------------------------------------------
|
||||
if options.polyfit
|
||||
if options.polyfit && n > 0
|
||||
hold on
|
||||
for i = 1:n
|
||||
ln = lines(n-i+1);
|
||||
x = ln.XData(:);
|
||||
y = ln.YData(:);
|
||||
dataObj = dataObjects(n-i+1);
|
||||
x = dataObj.XData(:);
|
||||
y = dataObj.YData(:);
|
||||
valid = isfinite(x) & isfinite(y);
|
||||
|
||||
if sum(valid) < options.polyorder+1
|
||||
@@ -112,7 +131,15 @@ if options.polyfit
|
||||
yf = polyval(p,xf);
|
||||
end
|
||||
|
||||
lightcol = ln.Color + 0.4*(1-ln.Color);
|
||||
if isa(dataObj,'matlab.graphics.chart.primitive.Line')
|
||||
basecol = dataObj.Color;
|
||||
else
|
||||
basecol = dataObj.CData(1,:);
|
||||
if numel(basecol) ~= 3
|
||||
basecol = cmap(i,:);
|
||||
end
|
||||
end
|
||||
lightcol = basecol + 0.4*(1-basecol);
|
||||
lightcol(lightcol>1)=1;
|
||||
|
||||
plot(xf,yf,'-','Color',lightcol,...
|
||||
|
||||
Reference in New Issue
Block a user