Figure export as .svg ends in .svg including a image

33 views (last 30 days)
Michael
Michael on 22 Oct 2025 at 11:00
Commented: dpb ungefär 16 timmar ago
Dear all,
today I ran into a “bug” I can’t solve and was wondering if anyone else has seen this before.
Here’s the situation: the full code works fine, and the figure displays exactly as expected. However, when I save the figure as an .svg file and open it in Inkscape, I lose editability — instead of individual elements, I just get - a sheep in a wolf's clothing - three layers, with the last one being a single image.
hold on
p = plot(range,abs(ifft_AB(:,1:9));
Name= ["-20 Names-"];
for i = 1:length(p)
set(p(i),DisplayName = Name(i), Color = col.Values(i,:),LineWidth=2)
end
plot(range,abs(ifft_AB(:,end)),Color=col.Values(i+1,:),DisplayName="XY",LineWidth=2)
After some testing, I found that the issue appears when I add a second plot() function. As soon as I include another plot command, the exported SVG turns into an image instead of keeping the editable vector elements. (Filename still is .svg!!) The first plot() with nine lines works perfectly. Restarting the machine and trying again gives the same result.
Has anyone experienced this before? Could this be related to how MATLAB handles multiple plot calls in SVG export, or is it a machine/driver issue? Could someone confirm the "bug"?
I’m using MATLAB 2023b, so I’m not sure if the problem still exists in the latest version.
Best regards
Michael
Here the full ploting part:
load_colors():
function [colorsShort, colorsLong] = load_colors()
% Short: struct Names, Values; colors are the basic one from the RUB
% Long: struct Names, Values; short plus some additional one
%% Begining plotting
%RUB used colors
rubblue=[0,55,90]/255;
rubgreen=[139,172,52]/255;
rubgrey=[127,127,127]/255;
rubyellow=[255,204,0]/255;
rubred=[183,30,63]/255;
rubdarkred = [183, 30, 63]/255;
rubbeige = [193, 186, 164]/255;
rubdarkgreen=[140, 135, 82]/255;
rubbrown=[156, 85, 22]/255;
rubdarkbrown=[89, 33, 28]/255;
colorsShort = struct();
colorsShort.Names = ["rubblue";"rubgreen";"rubgrey";"rubyellow";"rubred";"rubdarkred";...
"rubbeige";"rubdarkgreen";"rubbrown";"rubdarkbrown"];
colorsShort.Values = [rubblue;rubgreen;rubgrey;rubyellow;rubred;rubdarkred;...
rubbeige;rubdarkgreen;rubbrown;rubdarkbrown];
% if 10 coulors are not enough, some addition
black = [0 0 0]/255;
darkblue = [0 0 128]/255;
darkred = [153 0 0]/255;
darkgreen = [0 100 0]/255;
magenta = [204 0 153]/255;
orange = [204 102 0]/255;
grey = [129 129 129]/255;
red =[1 0 0];
blue=[0 0 1];
cyan= [0 1 1];
green=[0 1 0];
colorsLong = struct();
colorsLong.Names = ["rubblue";"rubgreen";"rubgrey";"rubyellow";"rubred";"rubdarkred";...
"rubbeige";"rubdarkgreen";"rubbrown";"rubdarkbrown";"black";"darkblue";...
"darkred";"darkgreen";"magenta";"orange";"grey";"red";"blue";"cyan";"green"];
colorsLong.Values = [rubblue;rubgreen;rubgrey;rubyellow;rubred;rubdarkred;...
rubbeige;rubdarkgreen;rubbrown;rubdarkbrown;black;darkblue;...
darkred;darkgreen;magenta;orange;grey;red;blue;cyan;green];
end
col = load_colors();
% figure configuration
fig = figure(1);
pause(0.5); % shor breake to build the figure
set(fig, 'WindowState', 'maximized'); % maximise the figure to screen dimensions
% general plot
hold on
p = plot(range,abs(ifft_AB(:,1:9)));
Name = ["300 mm","377 mm","455 mm","533 mm","611 mm","688 mm","766 mm",...
"844 mm","922 mm","1000 mm","3500 mm","1500 mm","2500 mm","1000 mmV2","1000 mmV3","3500 mmV3","1500 mmV3","2500 mmV3","2000 mmV3","3000 mmV3","Without Plate"];
for i = 1:length(p)
set(p(i),DisplayName = Name(i),Color=col.Values(i,:),LineWidth=2)
end
plot(range,abs(ifft_AB(:,end)),Color=col.Values(i+1,:),DisplayName="Without Plate",LineWidth=2)
% properties of current figure
grid on
box on
set(gca,'linewidth',2.5,'TickLabelInterpreter','latex')
ax = gca;
ax.YLim = [0 0.025]
ax.XLim = [0 1.5];
ax.FontSize = 35;
ax.XAxis.FontSize = 30;
ax.YAxis.FontSize = 30;
% labeling
xlabel('Distance in [m]','Interpreter','latex')
ylabel('|S11|','Interpreter','latex')
title('\textbf {Simulated reflection coefficient of a antenna-plate szenario}','Interpreter','latex');
subtitle(['Antenna influence substracted from plate results; distance offset of antenna (0.054m) retained'],'FontSize',28);
lgd = legend('Location','northeast','NumColumns',2,'FontSize',20,'Interpreter','latex');
title(lgd,'Plate distance')
%Set clasical Marker from MATLAB
%Plate05m = findobj(gcf, "DisplayName", "Without Plate");
%datatip(Plate05m,0.0539,0.022);
% Plate1m = findobj(gcf, "DisplayName", "300 mm");
% datatip(Plate1m,0.2698,0.00658);
% Plate1_5m = findobj(gcf, "DisplayName", "377 mm");
% datatip(Plate1_5m,0.3777,0.00499);
% Plate2m = findobj(gcf, "DisplayName", "455 mm");
% datatip(Plate2m,0.4856,0.00335);
% Plate3m = findobj(gcf, "DisplayName", "533 mm");
% datatip(Plate3m,0.62057,0.00250);
% --- Save as svg --- %
%Asking the user for the name before saving
prompt = 'Enter a name for saving:';
tit = 'Save Name';
defaultName = 'myData';
answer = inputdlg(prompt, tit, [1 50], {defaultName});
if isempty(answer)
disp('User cancelled');
return;
end
saveName = answer{1};
fprintf('User entered name: %s\n', saveName);
saveas(fig, [saveName,'.svg']);
clear p fig ax lgd
  5 Comments
Michael
Michael ungefär 4 timmar ago
Dear dpb,
I tried exporting as EPS with "exportgraphics" — it works, but unfortunately Inkscape doesn’t support .eps files. So, I have to open it with another program and convert it to .svg. It works, but it’s quite cumbersome.
(Export Graphics – Scalable Vector Graphics (SVG) [since R2025a])
Anyway, my goal wasn’t to find a workaround — I already have one and can get the results I need. My intention was to report the “bug” and see if it happens only to me. (The issue still occurs today, as described.)
In the meantime, I continued testing and noticed it only happens when I create a plot object. Using separate commands like plot(x1,y1); plot(x2,y2); works fine.
If this isn’t the right place to post it, please let me know. When I have more time, I’ll update to the latest version of MATLAB and check again there.
Best regards,
Michael
dpb
dpb ungefär 14 timmar ago
I'm not sure what you mean by "create a plot object"? All user-built plots are just a combination of commands. At what point in the creation of this figure would the behavior on saving change; that could be a significant clue.
As far as reporting, the Answers forum is not an official Mathworks support platform so if you want it to be looked at officially, you'll need to submit this to Mathworks as an official support request/bug at <Product Support Page>. I don't have linkscape so checking with it is out for me without having to go get it...
I do not know what the official policy of Mathworks is but I suspect even if it were determined to be a bug nothing would be done for R2023b but only for newer releases; I doubt they would roll patches back to earlier releases as new update, but I don't know that for certain.

Sign in to comment.

Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!