Saving figure as .svg alters appearance
Hi,
I’m making figures in MATLAB and want to export them in .svg to work with them in other programs. So far, that has been no problem, but I’m stumbling into something odd now. I’m trying to export this figure:
As you can see, this works fine in .png. This is also what the figure looks like in MATLAB. However, when I export as .svg, the blue patch that I plotted around the line to indicate the SEM continues until 10 seconds instead of 5:
I think this might be because I’m first plotting the patch, and then alter the x axis. However, this is not visible in the matlab figure, and the red and green patches show no problem for this.
My code is as follows:
xaxeslimits = [-5 5];
f = figure(‘InvertHardcopy’,’off’,’Color’,[1 1 1]);
t = tiledlayout(size(ROIs,2)/2, 2);
x = linspace(-5, 10, 226);
tileind = 2;
for roi = 1:size(ROIs, 2)
nexttile(tileind)
title(ROInames{roi})
eval([‘yhbo = means.hbo.’ ROIs{roi} ‘;’])
eval([‘SEMhbo = sems.hbo.’ ROIs{roi} ‘;’])
eval([‘yhbr = means.hbr.’ ROIs{roi} ‘;’])
eval([‘SEMhbr = sems.hbr.’ ROIs{roi} ‘;’])
eval([‘y = means.fluo.’ ROIs{roi} ‘;’])
eval([‘SEM = sems.fluo.’ ROIs{roi} ‘;’])
y = y-1; % to get centered around 0
% HbO
yyaxis right
plot(x, yhbo, ‘Color’, ‘red’, ‘LineWidth’, 2)
patch([x, fliplr(x)], [yhbo + SEMhbo fliplr(yhbo – SEMhbo)], ‘r’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
hold on
% HbR
plot(x, yhbr, ‘Color’, ‘blue’, ‘LineStyle’, ‘-‘, ‘LineWidth’, 2)
patch([x, fliplr(x)], [yhbr + SEMhbr fliplr(yhbr – SEMhbr)], ‘b’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
ylim([-1.5 1.5]);
h_label = ylabel(‘Delta muM’, ‘interpreter’, ‘Tex’, ‘Rotation’, 270);
ax = gca;
ax.YColor = ‘red’;
ax.XColor = ‘k’;
set(ax, ‘FontSize’, 15, ‘LineWidth’, 2)
xlim(xaxeslimits);
% Fluo
yyaxis left
plot(x,y, ‘Color’, [0.4660 0.6740 0.1880], ‘LineWidth’, 2);
patch([x, fliplr(x)], [y + SEM fliplr(y – SEM)], ‘g’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
f_label = ylabel(‘Delta F/F’);
ylim([-0.05 0.05]); % centered at 0
ax = gca;
ax.YColor = [0.4660 0.6740 0.1880];
ax.XColor = ‘k’;
set(ax, ‘FontSize’, 15, ‘LineWidth’, 2)
xlabel(‘Time (sec)’)
xlim(xaxeslimits);
if tileind == size(ROIs, 2)
tileind = 1;
else
tileind = tileind+2;
end
end
leg1 = legend({‘GCaMP’, ‘SEM’, ‘HbO’,’SEM’, ‘HbR’,’SEM’}, ‘Orientation’, ‘Horizontal’);
leg1.Location = ‘southoutside’;
% f.Position = [10 10 1800 1000];
f.Position = [10 10 900 1000];
% save
pause(0.5)
% saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.tiff’], ‘tiff’);
% saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.eps’], ‘epsc’);
saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.svg’], ‘svg’);
close(f)
Does anybody know how to fix this? I’d like to be able to easily alter the x-axis and have it still work.
Best,
MarleenHi,
I’m making figures in MATLAB and want to export them in .svg to work with them in other programs. So far, that has been no problem, but I’m stumbling into something odd now. I’m trying to export this figure:
As you can see, this works fine in .png. This is also what the figure looks like in MATLAB. However, when I export as .svg, the blue patch that I plotted around the line to indicate the SEM continues until 10 seconds instead of 5:
I think this might be because I’m first plotting the patch, and then alter the x axis. However, this is not visible in the matlab figure, and the red and green patches show no problem for this.
My code is as follows:
xaxeslimits = [-5 5];
f = figure(‘InvertHardcopy’,’off’,’Color’,[1 1 1]);
t = tiledlayout(size(ROIs,2)/2, 2);
x = linspace(-5, 10, 226);
tileind = 2;
for roi = 1:size(ROIs, 2)
nexttile(tileind)
title(ROInames{roi})
eval([‘yhbo = means.hbo.’ ROIs{roi} ‘;’])
eval([‘SEMhbo = sems.hbo.’ ROIs{roi} ‘;’])
eval([‘yhbr = means.hbr.’ ROIs{roi} ‘;’])
eval([‘SEMhbr = sems.hbr.’ ROIs{roi} ‘;’])
eval([‘y = means.fluo.’ ROIs{roi} ‘;’])
eval([‘SEM = sems.fluo.’ ROIs{roi} ‘;’])
y = y-1; % to get centered around 0
% HbO
yyaxis right
plot(x, yhbo, ‘Color’, ‘red’, ‘LineWidth’, 2)
patch([x, fliplr(x)], [yhbo + SEMhbo fliplr(yhbo – SEMhbo)], ‘r’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
hold on
% HbR
plot(x, yhbr, ‘Color’, ‘blue’, ‘LineStyle’, ‘-‘, ‘LineWidth’, 2)
patch([x, fliplr(x)], [yhbr + SEMhbr fliplr(yhbr – SEMhbr)], ‘b’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
ylim([-1.5 1.5]);
h_label = ylabel(‘Delta muM’, ‘interpreter’, ‘Tex’, ‘Rotation’, 270);
ax = gca;
ax.YColor = ‘red’;
ax.XColor = ‘k’;
set(ax, ‘FontSize’, 15, ‘LineWidth’, 2)
xlim(xaxeslimits);
% Fluo
yyaxis left
plot(x,y, ‘Color’, [0.4660 0.6740 0.1880], ‘LineWidth’, 2);
patch([x, fliplr(x)], [y + SEM fliplr(y – SEM)], ‘g’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
f_label = ylabel(‘Delta F/F’);
ylim([-0.05 0.05]); % centered at 0
ax = gca;
ax.YColor = [0.4660 0.6740 0.1880];
ax.XColor = ‘k’;
set(ax, ‘FontSize’, 15, ‘LineWidth’, 2)
xlabel(‘Time (sec)’)
xlim(xaxeslimits);
if tileind == size(ROIs, 2)
tileind = 1;
else
tileind = tileind+2;
end
end
leg1 = legend({‘GCaMP’, ‘SEM’, ‘HbO’,’SEM’, ‘HbR’,’SEM’}, ‘Orientation’, ‘Horizontal’);
leg1.Location = ‘southoutside’;
% f.Position = [10 10 1800 1000];
f.Position = [10 10 900 1000];
% save
pause(0.5)
% saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.tiff’], ‘tiff’);
% saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.eps’], ‘epsc’);
saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.svg’], ‘svg’);
close(f)
Does anybody know how to fix this? I’d like to be able to easily alter the x-axis and have it still work.
Best,
Marleen Hi,
I’m making figures in MATLAB and want to export them in .svg to work with them in other programs. So far, that has been no problem, but I’m stumbling into something odd now. I’m trying to export this figure:
As you can see, this works fine in .png. This is also what the figure looks like in MATLAB. However, when I export as .svg, the blue patch that I plotted around the line to indicate the SEM continues until 10 seconds instead of 5:
I think this might be because I’m first plotting the patch, and then alter the x axis. However, this is not visible in the matlab figure, and the red and green patches show no problem for this.
My code is as follows:
xaxeslimits = [-5 5];
f = figure(‘InvertHardcopy’,’off’,’Color’,[1 1 1]);
t = tiledlayout(size(ROIs,2)/2, 2);
x = linspace(-5, 10, 226);
tileind = 2;
for roi = 1:size(ROIs, 2)
nexttile(tileind)
title(ROInames{roi})
eval([‘yhbo = means.hbo.’ ROIs{roi} ‘;’])
eval([‘SEMhbo = sems.hbo.’ ROIs{roi} ‘;’])
eval([‘yhbr = means.hbr.’ ROIs{roi} ‘;’])
eval([‘SEMhbr = sems.hbr.’ ROIs{roi} ‘;’])
eval([‘y = means.fluo.’ ROIs{roi} ‘;’])
eval([‘SEM = sems.fluo.’ ROIs{roi} ‘;’])
y = y-1; % to get centered around 0
% HbO
yyaxis right
plot(x, yhbo, ‘Color’, ‘red’, ‘LineWidth’, 2)
patch([x, fliplr(x)], [yhbo + SEMhbo fliplr(yhbo – SEMhbo)], ‘r’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
hold on
% HbR
plot(x, yhbr, ‘Color’, ‘blue’, ‘LineStyle’, ‘-‘, ‘LineWidth’, 2)
patch([x, fliplr(x)], [yhbr + SEMhbr fliplr(yhbr – SEMhbr)], ‘b’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
ylim([-1.5 1.5]);
h_label = ylabel(‘Delta muM’, ‘interpreter’, ‘Tex’, ‘Rotation’, 270);
ax = gca;
ax.YColor = ‘red’;
ax.XColor = ‘k’;
set(ax, ‘FontSize’, 15, ‘LineWidth’, 2)
xlim(xaxeslimits);
% Fluo
yyaxis left
plot(x,y, ‘Color’, [0.4660 0.6740 0.1880], ‘LineWidth’, 2);
patch([x, fliplr(x)], [y + SEM fliplr(y – SEM)], ‘g’ ,’EdgeColor’,’none’, ‘FaceAlpha’,0.25)
f_label = ylabel(‘Delta F/F’);
ylim([-0.05 0.05]); % centered at 0
ax = gca;
ax.YColor = [0.4660 0.6740 0.1880];
ax.XColor = ‘k’;
set(ax, ‘FontSize’, 15, ‘LineWidth’, 2)
xlabel(‘Time (sec)’)
xlim(xaxeslimits);
if tileind == size(ROIs, 2)
tileind = 1;
else
tileind = tileind+2;
end
end
leg1 = legend({‘GCaMP’, ‘SEM’, ‘HbO’,’SEM’, ‘HbR’,’SEM’}, ‘Orientation’, ‘Horizontal’);
leg1.Location = ‘southoutside’;
% f.Position = [10 10 1800 1000];
f.Position = [10 10 900 1000];
% save
pause(0.5)
% saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.tiff’], ‘tiff’);
% saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.eps’], ‘epsc’);
saveas(gcf, [SaveDir ‘/NVC/Sham_RS/’ Acq ‘_’ type ‘_’ ROIsavename ‘_AvCurves.svg’], ‘svg’);
close(f)
Does anybody know how to fix this? I’d like to be able to easily alter the x-axis and have it still work.
Best,
Marleen image export, svg, plotting, figure export MATLAB Answers — New Questions