yline disappeared after closing a saved figure when reopening

5 次查看(过去 30 天)
Hi, I am creating a figure with multiple axis (such as subplot but manually). Part of the figure are also multiple xlines. When creating the figure with my script everything seems to work fine. I also save the figure and let the script close it automatically. When reopening the saved *.fig file the xlines disappeared and I have no clue what to try next.
fh = struct([]); % figurehandler which holds 4 axies all similar built like ax3
fh(k1).fh = figure; % k1 is a counter in a for loop
fh(k1).ax3 = axes(fh(k1).fh);
fh(k1).ax3.Position = [0.06,0.25,0.7,0.2];
fh(k1).ax3.YLim = [-1 1];
grid(fh(k1).ax3,"on");
hold(fh(k1).ax3, "on");
fh(k1).ax3.XLim = [-0.01 inf];
yyaxis(fh(k1).ax3,"left");
hold(fh(k1).ax3, "on");
linkaxes([fh(k1).ax, fh(k1).ax3], "x");
yline(fh(k1).ax3, [value1_std -value1_std],"--b","DisplayName","Value1");
yyaxis(fh(k1).ax3,"right");
hold(fh(k1).ax3, "on"); % added the holds to make sure nothing will be overwritten
yline(fh(k1).ax3, [value2_std -value2_std],"--", "Color",[0.8500, 0.3250, 0.0980],"DisplayName","Value2");
hold([fh(k1).ax,fh(k1).ax2,fh(k1).ax3,fh(k1).ax4], "off");
%saveas(fh(k1).fh,fullfile(savefolder,{sprintf('Step%d.fig', k1)})); %
%tried this but causes the same issue
savefig(fh(k1).fh,fullfile(savefolder,{sprintf('Step%d.fig', k1)}));
print(fh(k1).fh,fullfile(savefolder,{sprintf('Step%d', k1)}),"-dpng","-r400");
close(fh(k1).fh);
However when saving the figure as png the lines are there, as they were when i created the plot. Both ylines disappeared
  5 个评论
John Pausder
John Pausder 2024-3-21
@Jonas as have you been able to recreate the issue? When I run your code snipped and place a breakpoint just before closing the fig, I can see the ylines. Yet, as I reopen the saved figure they are gone just as I described..
Jonas
Jonas 2024-4-2
@John Pausder no, i cannot reproduce this. everything fine running on 2022a. i can see both ylines

请先登录,再进行评论。

回答(1 个)

Animesh
Animesh 2024-2-28
I have been encountering a similar issue while working with “xline and “yyaxis. The only workaround I can think of is to use “line” instead ofyline”.
Here is something you can do to replicate the similar behaviour using “line”:
% Left Y-axis
yyaxis(fh(k1).ax3, "left");
hold(fh(k1).ax3, "on");
% Draw a line at y = 0.5 using the `line` function
x_values = fh(k1).ax3.XLim; % Use current x-axis limits
line(x_values, [0.5 0.5], 'LineStyle', '--', 'Color', 'b', 'Parent', fh(k1).ax3, 'DisplayName', 'Value1');
% Right Y-axis
yyaxis(fh(k1).ax3, "right");
hold(fh(k1).ax3, "on");
% Draw a line at y = 5 using the `line` function
line(x_values, [5 5], 'LineStyle', '--', 'Color', [0.8500, 0.3250, 0.0980], 'Parent', fh(k1).ax3, 'DisplayName', 'Value2');
You can refer the following MathWorks documentation for more information on "line"
  1 个评论
John Pausder
John Pausder 2024-3-21
编辑:John Pausder 2024-3-21
Thank you @Animesh. I also used another workaround by creating a vecotor with the length of the represented data, just as one value and plotted this. I think yours is the better option.
c_std_vec = zeros(length(data(datastart:dataend)) ,2);
c_std_vec(:,1) = data.std;
c_std_vec(:,2) = - data.std;
plot(fh(k1).ax3, timedata(datastart:dataend), c_std_v

请先登录,再进行评论。

类别

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

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by