centralized thesis figure plotting scripts
This commit is contained in:
1 parent
dd5a0fd103
commit
a55798c599
4 files changed
+272
-60
No files matched your search
+42
-11
@@ -5,8 +5,12 @@ function f = exportThesisFig(f, name, aspect, opts)
|
||||
% exportThesisFig(f, "sigmoidmodel") % full width, 4:3
|
||||
% exportThesisFig(f, "traj", 1, Width=230) % half-width subfigure
|
||||
% exportThesisFig(f, "traj", 3/4, LineStyles=true) % distinguishable in grayscale
|
||||
% exportThesisFig(f, "perf", 0.8, Width=330) % imagesc plot -> name.png
|
||||
%
|
||||
% The figure is modified in place.
|
||||
% Figures containing images (imagesc, image) are exported as a lossless
|
||||
% 400 dpi PNG instead: MATLAB's vector PDF export draws them with a
|
||||
% visible diagonal seam. The PNG records its dpi, so LaTeX still places it
|
||||
% at Width points. The figure is modified in place.
|
||||
arguments (Input)
|
||||
f (1, 1) {mustBeA(f, "matlab.ui.Figure")};
|
||||
name (1, 1) string;
|
||||
@@ -15,11 +19,17 @@ function f = exportThesisFig(f, name, aspect, opts)
|
||||
opts.FontSize (1, 1) double {mustBePositive} = 10; % \footnotesize in a 12pt doc
|
||||
opts.LineWidth (1, 1) double {mustBePositive} = 2; % data lines, points
|
||||
opts.AxesLineWidth (1, 1) double {mustBePositive} = 0.75;
|
||||
opts.MarkerSize (1, 1) double {mustBePositive} = 4;
|
||||
opts.MarkerSize (1, 1) double {mustBePositive} = 4; % markers on lines
|
||||
opts.PointMarkerSize (1, 1) double {mustBePositive} = 16; % marker-only series, e.g. plot(x, y, "k+")
|
||||
opts.PointMarkerLineWidth (1, 1) double {mustBePositive} = 2.5;
|
||||
opts.Palette (:, 3) double = okabeIto(); % colorblind- and print-safe
|
||||
opts.Recolor (1, 1) logical = true; % also override explicitly set colors
|
||||
opts.LineStyles (1, 1) logical = false; % cycle line styles per series
|
||||
opts.Raster (1, 1) logical = false; % for very dense plots
|
||||
opts.Raster (1, 1) logical = ~isempty(findall(f, 'Type', 'image')); % PNG; also for very dense plots
|
||||
% dpi, for Raster. MATLAB silently writes an all-black PNG when the image is
|
||||
% too large (3909 px wide failed, 2750 px worked), so full width stays at 400
|
||||
opts.Resolution (1, 1) double {mustBePositive} = 400;
|
||||
opts.Colormap = []; % for images/surfaces, e.g. "parula"; [] keeps the figure's
|
||||
opts.OutDir (1, 1) string = matlab.project.rootProject().RootFolder;
|
||||
end
|
||||
arguments (Output)
|
||||
@@ -41,6 +51,17 @@ function f = exportThesisFig(f, name, aspect, opts)
|
||||
if opts.LineStyles
|
||||
ax.LineStyleOrder = styles;
|
||||
end
|
||||
if ~isempty(opts.Colormap)
|
||||
colormap(ax, opts.Colormap);
|
||||
end
|
||||
end
|
||||
|
||||
% Colorbars (image and surface plots) get the same frame as the axes. Their
|
||||
% Label isn't reached by findall above, so set it directly.
|
||||
for cb = findall(f, 'Type', 'colorbar')'
|
||||
cb.LineWidth = opts.AxesLineWidth;
|
||||
cb.Label.Interpreter = 'latex';
|
||||
cb.Label.FontSize = opts.FontSize;
|
||||
end
|
||||
|
||||
% Data series. SeriesIndex is the series' position in its axes' color
|
||||
@@ -57,11 +78,21 @@ function f = exportThesisFig(f, name, aspect, opts)
|
||||
isLine = isprop(s, 'Color');
|
||||
isScatter = isa(s, 'matlab.graphics.chart.primitive.Scatter');
|
||||
|
||||
if isLine || isScatter
|
||||
s.LineWidth = opts.LineWidth;
|
||||
end
|
||||
if isprop(s, 'MarkerSize')
|
||||
s.MarkerSize = opts.MarkerSize;
|
||||
% Marker-only series (no connecting line) mark individual points; a
|
||||
% thick data-line width would fill in markers like + and x
|
||||
isPoint = isLine && isprop(s, 'Marker') && strcmp(s.LineStyle, 'none') ...
|
||||
&& ~strcmp(s.Marker, 'none');
|
||||
|
||||
if isPoint
|
||||
s.LineWidth = opts.PointMarkerLineWidth;
|
||||
s.MarkerSize = opts.PointMarkerSize;
|
||||
else
|
||||
if isLine || isScatter
|
||||
s.LineWidth = opts.LineWidth;
|
||||
end
|
||||
if isprop(s, 'MarkerSize')
|
||||
s.MarkerSize = opts.MarkerSize;
|
||||
end
|
||||
end
|
||||
if opts.LineStyles && isLine && ~strcmp(s.LineStyle, 'none')
|
||||
s.LineStyle = styles(mod(k - 1, numel(styles)) + 1);
|
||||
@@ -89,9 +120,9 @@ function f = exportThesisFig(f, name, aspect, opts)
|
||||
f.PaperSize = [w, h];
|
||||
|
||||
if opts.Raster
|
||||
renderer = {'-image', '-r300'};
|
||||
% PNG rather than '-dpdf -image', which embeds a lossy JPEG
|
||||
print(f, fullfile(opts.OutDir, name + ".png"), '-dpng', "-r" + opts.Resolution);
|
||||
else
|
||||
renderer = {'-vector'};
|
||||
print(f, fullfile(opts.OutDir, name + ".pdf"), '-dpdf', '-vector');
|
||||
end
|
||||
print(f, fullfile(opts.OutDir, name + ".pdf"), '-dpdf', renderer{:});
|
||||
end
|
||||
Reference in new issue
Block a user