Skip to content

Commit

Permalink
Changing readme graphics to svg
Browse files Browse the repository at this point in the history
  • Loading branch information
btmy87 committed Sep 7, 2024
1 parent 55bdf2f commit 0b06db3
Show file tree
Hide file tree
Showing 8 changed files with 2,082 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ passed directly to plot calls. Errorbars are automatically configured.
Correlated errors are plotted as ellipses.

<picture>
<source media="(prefers-color-scheme: dark)" srcset="resources/dark.png">
<source media="(prefers-color-scheme: light)" srcset="resources/light.png">
<img alt="Example plot with error bars." src="resources/opaque.png">
<source media="(prefers-color-scheme: dark)" srcset="resources/dark.svg">
<source media="(prefers-color-scheme: light)" srcset="resources/light.svg">
<img alt="Example plot with error bars." src="resources/opaque.svg">
</picture>
40 changes: 33 additions & 7 deletions make_graphics.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
y = x.^2 + UncVal(0, 0.04, "y");

%% Make light plot
figure(Name="light", ...
hf = figure(Name="light", ...
Color="w", ...
defaultAxesColor="w", ...
defaultAxesXColor=[0.15, 0.15, 0.15], ...
Expand All @@ -18,23 +18,26 @@
defaultAxesYGrid="on", ...
defaultAxesBox="on", ...
defaultTextColor=[0.15, 0.15, 0.15], ...
defaultAxesFontSize=14, ...
defaultAxesFontSize=11, ...
defaultErrorBarLineWidth=1.5, ...
defaultLineLineWidth=1.5, ...
defaultLineMarkerFaceColor="w", ...
defaultAxesLineWidth=1.5, ...
defaultAxesGridLineWidth=1.0, ...
defaultAxesGridAlpha=0.3, ...
defaultTextFontName="FixedWidth", ...
defaultAxesFontName="FixedWidth", ...
Units="pixels", ...
Position=[10, 10, 800, 500]);

t = tiledlayout("flow", padding="compact", TileSpacing="compact");
title(t, "UncVal Plotting Options", FontSize=14);
title(t, "UncVal Plotting Options");
nexttile;hold on;xlabel("x");ylabel("y");
title("plot command", FontWeight="normal");
plot(x, y);

t.Title.Color = get(gca, "XColor"); % I have some funny defaults
t.Title.FontName = get(gca, "FontName");

ha = nexttile;hold on;xlabel("x");ylabel("y");
title("errorbar, x-only", FontWeight="normal")
Expand All @@ -51,11 +54,25 @@
if ~exist("resources", "dir")
mkdir("resources");
end
write_png(gcf, "resources/light.png");
saveas(gcf, "resources/opaque.png");
% hf.Color = "none";
% set(findobj(hf, "Type", "Axes"), "Color", "none");
% print(hf, "resources/light.svg", "-dsvg");

delete("resources/opaque.svg");
print(hf, "resources/opaque.svg", "-dsvg");
opaqueLines = readlines("resources/opaque.svg");
lightLines = regexprep(opaqueLines, "fill:white", "fill:none");
writelines(lightLines, "resources/light.svg", WriteMode="overwrite");

% write_png(hf, "resources/light.png");
% saveas(hf, "resources/opaque.png");
%
% hf.Color = "none";
% set(findobj(hf, "Type", "Axes"), "Color", "none");


%% Make dark plot
figure(Name="dark", ...
hf = figure(Name="dark", ...
Color=[0, 0, 0], ...
defaultAxesColor=[0, 0, 0], ...
defaultAxesXColor=[1,1,1].*230/255, ...
Expand All @@ -72,6 +89,9 @@
defaultAxesLineWidth=1.5, ...
defaultAxesGridLineWidth=1.0, ...
defaultAxesGridAlpha=0.3, ...
defaultTextFontName="FixedWidth", ...
defaultAxesFontName="FixedWidth", ...
InvertHardcopy="off", ...
Units="pixels", ...
Position=[10, 10, 800, 500]);

Expand All @@ -82,6 +102,7 @@
plot(x, y);

t.Title.Color = get(gca, "XColor"); % I have some funny defaults
t.Title.FontName = get(gca, "FontName");

ha = nexttile;hold on;xlabel("x");ylabel("y");
title("errorbar, x-only", FontWeight="normal")
Expand All @@ -95,7 +116,12 @@
title("errorbar, x and y", FontWeight="normal")
errorbar(x, y);

write_png(gcf, "resources/dark.png");
% write_png(gcf, "resources/dark.png");
delete("resources/dark.svg");
print(hf, "resources/dark.svg", "-dsvg");
tempLines = readlines("resources/dark.svg");
darkLines = regexprep(tempLines, "fill:black", "fill:none");
writelines(darkLines, "resources/dark.svg", WriteMode="overwrite");

%% Utility function
function write_png(hf, filename)
Expand Down
Binary file removed resources/dark.png
Binary file not shown.
586 changes: 586 additions & 0 deletions resources/dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/light.png
Binary file not shown.
730 changes: 730 additions & 0 deletions resources/light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/opaque.png
Binary file not shown.
730 changes: 730 additions & 0 deletions resources/opaque.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0b06db3

Please sign in to comment.