Saving my subplots as SVG cuts off one of my subplots and removes plotting data of one of them

4 次查看(过去 30 天)
Hi all,
I am using Matlab 2024b, and am using the new desktop version. Currently I am trying to save one of my figures (containing four subplots) as an SVG, but it just cuts off one of the subplots and removes the plotting in the third subplot.
This is what I am trying to save:
And this is what it looks like in illustrator (it is a screenshot of illustrator, so the extra vertical lines you see are from illustrator itself)
I am unsure what is going wrong, but I would like to have the SVG for editing purposes. Below is the code of the function that I used to plot this figure. Many thanks in advance for anyone willing to look at this with me!
function typical_data_plots = plot_typical_vars(ds, dI, i_sstart_t, i_send_t, trial_label)
% Set xlimits
limitx = [0 4500];
% Get x_axis data
Fc_x = dI.Fc_x;
ROA_x1 = dI.ROA_ax1; % icor local frame
% Get y_axis data
% 1. IROC
IROC_t = dI.ROC;
% 2. Lin accel xyz
lacc_x = ds.Hx(i_sstart_t:i_send_t);
lacc_y = ds.Hy(i_sstart_t:i_send_t);
lacc_z = ds.Hz(i_sstart_t:i_send_t);
% 3. Rotational velocity and accel, sagittal
rac = ds.HRacc(i_sstart_t:i_send_t);
rav = ds.HR1(i_sstart_t:i_send_t);
% 4. Fc_z trajectory
Fc_z = dI.Fc_z;
% 5. ICOR local frame
ROA_x2 = dI.ROA_ax2;
% plot
% Set custom tick positions
tickPos = [0:500:4500];
tickPos = unique(tickPos);
f1 = figure;
% 1. IROR
subplot(4,1,1);
semilogy(Fc_x, IROC_t, 'b');
% Find max absolute values for ylim set
xlim(limitx);
ylim([1 1000]);
yticks([1 10 100 1000]);
ylabel('IROR (mm)');
title(['IROR, linear accelerations and angular vel and accel of ' trial_label], 'Interpreter', 'none');
% Add xticklabels in meters
ax = gca;
tickLabels = arrayfun(@(x) sprintf('%.1f', x/1000), tickPos, ...
'UniformOutput', false);
ax.XTick = tickPos;
ax.XTickLabel = tickLabels;
% 2. Lin accel xyz
subplot(4,1,2);
plot(Fc_x,lacc_x,'b','DisplayName','X');
hold on;
plot(Fc_x,lacc_y,'--','DisplayName','Y');
plot(Fc_x,lacc_z,':','DisplayName','Z');
hold off;
ylim([-270 270]);
xlim(limitx);
legend('Box', 'off', BackgroundAlpha=.7);
ylabel('Linear acceleration (m/s^2)');
%Convert xlabels to meters
ax = gca;
tickLabels = arrayfun(@(x) sprintf('%.1f', x/1000), tickPos, ...
'UniformOutput', false); % Convert to meters for labels
ax.XTick = tickPos;
ax.XTickLabel = tickLabels;
% 3. Rotational velocity and accel, sagittal
subplot(4,1,3);
hold on;
yyaxis left;
plot(Fc_x,rav,'b','DisplayName','\omega');
ylim([-30 30]);
ylabel('Angular velocity (rad/s)');
yyaxis right;
plot(Fc_x,rac,'--','DisplayName','\alpha');
ylim([-2100 2100]);
ylabel('Angular acceleration (rad/s^2)');
xlim(limitx);
% Convert xlabels to meters
ax = gca;
tickLabels = arrayfun(@(x) sprintf('%.1f', x/1000), tickPos, ...
'UniformOutput', false); % Convert to meters for labels
ax.XTick = tickPos;
ax.XTickLabel = tickLabels;
%xlabel('x position of Fc (mm)');
legend('Box', 'off', BackgroundAlpha=.7);
hold off;
% 4. Fc_x vs Fc_y
subplot(4,1,4);
plot(Fc_x,Fc_z,'b');
ylabel('Z position of Fc (mm)');
xlim(limitx);
ylim([200 600]);
xlabel('X position of Fc (m)');
% For subplot number 4,
ax = gca;
ax.XTick = tickPos;
ax.XTickLabel = tickLabels;
% add vertical lines
hold(ax, 'on');
xline(ax, 600, '--k');
xline(ax, 2600, '--k');
hold(ax, 'off');
typical_data_plots = f1;
end

回答(1 个)

Epsilon
Epsilon 2025-8-4
Hi Puck,
This behavior occurs because the “saveas” function and the Save As dialog box may encounter renderer limitations, particularly with complex plots. To work around this, you can set the renderer to OpenGL by running the following command before saving your figure:
set(gcf,'Renderer','opengl');
This directs MATLAB to use your graphics hardware, which can help stabilize the export process and should resolve the issue.
For saving graphics, the recommended approach is to use the “exportgraphics” function. However, please note that saving to SVG format with “exportgraphics” is only supported in MATLAB R2025a and later releases and might not be useful in your case.
  2 个评论
Puck
Puck 2025-8-6
Hi,
Thank you so much for your answer. I will apply your suggestion of set(gcf,'Renderer','opengl') next week, and will let you know how it will go.
At this moment I am hesitant to update to MATLAB R2025a because some things in my analysis code might not work properly anymore in that version, but I will definitely that into account in the future.
I will get back to your answer!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by